Previous 199869 Revisions Next

r22723 Thursday 9th May, 2013 at 14:32:21 UTC by Miodrag Milanović
added emu.keypost function to lua, and made autoboot_command execute that one instead of direct execution, note that you need to add \n for new line at the end now (nw)
[src/emu]luaengine.c luaengine.h machine.c

trunk/src/emu/luaengine.c
r22722r22723
5353//  emu_gamename - returns game full name
5454//-------------------------------------------------
5555
56int lua_engine::emu_gamename(lua_State *L) {
56int lua_engine::emu_gamename(lua_State *L)
57{
5758   lua_pushstring(L, luaThis->machine().system().description);
5859   return 1;
5960}
6061
62//-------------------------------------------------
63//  emu_keypost - post keys to natural keyboard
64//-------------------------------------------------
65
66int 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
6173static const struct luaL_Reg emu_funcs [] =
6274{
6375  { "gamename", lua_engine::emu_gamename },
76  { "keypost", lua_engine::emu_keypost },
6477  { NULL, NULL }  /* sentinel */
6578};
6679
r22722r22723
141154  }
142155}
143156
144
145157//-------------------------------------------------
146//  execute - setup lua VM and load script
158//  createvm - setup lua VM and load script
147159//-------------------------------------------------
148160
149void lua_engine::execute(const char *filename)
161void lua_engine::createvm()
150162{
151163   close();
152164   
r22722r22723
155167   luaL_openlibs(m_lua_state);
156168   luaL_requiref(m_lua_state, "emu", luaopen_emu, 1);   
157169   lua_sethook(m_lua_state, hook, LUA_MASKLINE, 0);     
170}
158171
172//-------------------------------------------------
173//  execute - load and execute script
174//-------------------------------------------------
175
176void lua_engine::execute(const char *filename)
177{
178   createvm();   
179   
159180   int s = luaL_loadfile(m_lua_state, filename);       
160181   report_errors(s);
161182
r22722r22723
163184}
164185
165186//-------------------------------------------------
187//  execute_string - execute script from string
188//-------------------------------------------------
189
190void 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//-------------------------------------------------
166200//  lua_execute - execute slice of lua script
167201//  this callback is hooked to frame notification
168202//-------------------------------------------------
trunk/src/emu/luaengine.h
r22722r22723
6262   void lua_execute();
6363   void report_errors(int status);
6464   
65   void execute(const char *filename);
66   
65   void createvm();
66   void execute(const char *filename);   
67   void execute_string(const char *value);
6768   void close();
6869   
6970   //static
7071   static int emu_gamename(lua_State *L);
72   static int emu_keypost(lua_State *L);
7173private:   
7274   // internal state
7375   running_machine &   m_machine;                          // reference to our machine
trunk/src/emu/machine.c
r22722r22723
239239      m_lua_engine.execute(options().autoboot_script());
240240   }
241241   if (strlen(options().autoboot_command())!=0) {
242      astring val = astring(options().autoboot_command());
243      val.replace("\\n","\n");
244      val.replace("\\r","\r");
245      ioport().natkeyboard().post_utf8(val);
246      ioport().natkeyboard().post_utf8("\r");   
242      astring cmd = astring(options().autoboot_command());
243      cmd.replace("'","\\'");
244      astring val = astring("emu.keypost('",cmd,"')");
245      m_lua_engine.execute_string(val);
247246   }
248247}
249248

Previous 199869 Revisions Next


© 1997-2024 The MAME Team