trunk/src/emu/luaengine.c
| r22722 | r22723 | |
| 53 | 53 | // emu_gamename - returns game full name |
| 54 | 54 | //------------------------------------------------- |
| 55 | 55 | |
| 56 | | int lua_engine::emu_gamename(lua_State *L) { |
| 56 | int lua_engine::emu_gamename(lua_State *L) |
| 57 | { |
| 57 | 58 | lua_pushstring(L, luaThis->machine().system().description); |
| 58 | 59 | return 1; |
| 59 | 60 | } |
| 60 | 61 | |
| 62 | //------------------------------------------------- |
| 63 | // emu_keypost - post keys to natural keyboard |
| 64 | //------------------------------------------------- |
| 65 | |
| 66 | int lua_engine::emu_keypost(lua_State *L) |
| 67 | { |
| 68 | const char *keys = luaL_checkstring(L,1); |
| 69 | luaThis->machine().ioport().natkeyboard().post_utf8(keys); |
| 70 | return 1; |
| 71 | } |
| 72 | |
| 61 | 73 | static const struct luaL_Reg emu_funcs [] = |
| 62 | 74 | { |
| 63 | 75 | { "gamename", lua_engine::emu_gamename }, |
| 76 | { "keypost", lua_engine::emu_keypost }, |
| 64 | 77 | { NULL, NULL } /* sentinel */ |
| 65 | 78 | }; |
| 66 | 79 | |
| r22722 | r22723 | |
| 141 | 154 | } |
| 142 | 155 | } |
| 143 | 156 | |
| 144 | | |
| 145 | 157 | //------------------------------------------------- |
| 146 | | // execute - setup lua VM and load script |
| 158 | // createvm - setup lua VM and load script |
| 147 | 159 | //------------------------------------------------- |
| 148 | 160 | |
| 149 | | void lua_engine::execute(const char *filename) |
| 161 | void lua_engine::createvm() |
| 150 | 162 | { |
| 151 | 163 | close(); |
| 152 | 164 | |
| r22722 | r22723 | |
| 155 | 167 | luaL_openlibs(m_lua_state); |
| 156 | 168 | luaL_requiref(m_lua_state, "emu", luaopen_emu, 1); |
| 157 | 169 | lua_sethook(m_lua_state, hook, LUA_MASKLINE, 0); |
| 170 | } |
| 158 | 171 | |
| 172 | //------------------------------------------------- |
| 173 | // execute - load and execute script |
| 174 | //------------------------------------------------- |
| 175 | |
| 176 | void lua_engine::execute(const char *filename) |
| 177 | { |
| 178 | createvm(); |
| 179 | |
| 159 | 180 | int s = luaL_loadfile(m_lua_state, filename); |
| 160 | 181 | report_errors(s); |
| 161 | 182 | |
| r22722 | r22723 | |
| 163 | 184 | } |
| 164 | 185 | |
| 165 | 186 | //------------------------------------------------- |
| 187 | // execute_string - execute script from string |
| 188 | //------------------------------------------------- |
| 189 | |
| 190 | void lua_engine::execute_string(const char *value) |
| 191 | { |
| 192 | createvm(); |
| 193 | |
| 194 | int s = luaL_loadstring(m_lua_state, value); |
| 195 | report_errors(s); |
| 196 | |
| 197 | mame_printf_verbose("[LUA] Start executing script\n"); |
| 198 | } |
| 199 | //------------------------------------------------- |
| 166 | 200 | // lua_execute - execute slice of lua script |
| 167 | 201 | // this callback is hooked to frame notification |
| 168 | 202 | //------------------------------------------------- |