mirror of
https://github.com/libretro/mame.git
synced 2024-12-03 23:51:37 +00:00
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)
This commit is contained in:
parent
1827647369
commit
0c393edfdf
@ -53,14 +53,27 @@ lua_engine* lua_engine::luaThis = NULL;
|
||||
// emu_gamename - returns game full name
|
||||
//-------------------------------------------------
|
||||
|
||||
int lua_engine::emu_gamename(lua_State *L) {
|
||||
int lua_engine::emu_gamename(lua_State *L)
|
||||
{
|
||||
lua_pushstring(L, luaThis->machine().system().description);
|
||||
return 1;
|
||||
}
|
||||
|
||||
//-------------------------------------------------
|
||||
// emu_keypost - post keys to natural keyboard
|
||||
//-------------------------------------------------
|
||||
|
||||
int lua_engine::emu_keypost(lua_State *L)
|
||||
{
|
||||
const char *keys = luaL_checkstring(L,1);
|
||||
luaThis->machine().ioport().natkeyboard().post_utf8(keys);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const struct luaL_Reg emu_funcs [] =
|
||||
{
|
||||
{ "gamename", lua_engine::emu_gamename },
|
||||
{ "keypost", lua_engine::emu_keypost },
|
||||
{ NULL, NULL } /* sentinel */
|
||||
};
|
||||
|
||||
@ -141,12 +154,11 @@ void lua_engine::report_errors(int status)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// execute - setup lua VM and load script
|
||||
// createvm - setup lua VM and load script
|
||||
//-------------------------------------------------
|
||||
|
||||
void lua_engine::execute(const char *filename)
|
||||
void lua_engine::createvm()
|
||||
{
|
||||
close();
|
||||
|
||||
@ -155,13 +167,35 @@ void lua_engine::execute(const char *filename)
|
||||
luaL_openlibs(m_lua_state);
|
||||
luaL_requiref(m_lua_state, "emu", luaopen_emu, 1);
|
||||
lua_sethook(m_lua_state, hook, LUA_MASKLINE, 0);
|
||||
}
|
||||
|
||||
//-------------------------------------------------
|
||||
// execute - load and execute script
|
||||
//-------------------------------------------------
|
||||
|
||||
void lua_engine::execute(const char *filename)
|
||||
{
|
||||
createvm();
|
||||
|
||||
int s = luaL_loadfile(m_lua_state, filename);
|
||||
report_errors(s);
|
||||
|
||||
mame_printf_verbose("[LUA] Start executing script\n");
|
||||
}
|
||||
|
||||
//-------------------------------------------------
|
||||
// execute_string - execute script from string
|
||||
//-------------------------------------------------
|
||||
|
||||
void lua_engine::execute_string(const char *value)
|
||||
{
|
||||
createvm();
|
||||
|
||||
int s = luaL_loadstring(m_lua_state, value);
|
||||
report_errors(s);
|
||||
|
||||
mame_printf_verbose("[LUA] Start executing script\n");
|
||||
}
|
||||
//-------------------------------------------------
|
||||
// lua_execute - execute slice of lua script
|
||||
// this callback is hooked to frame notification
|
||||
|
@ -62,12 +62,14 @@ public:
|
||||
void lua_execute();
|
||||
void report_errors(int status);
|
||||
|
||||
void execute(const char *filename);
|
||||
|
||||
void createvm();
|
||||
void execute(const char *filename);
|
||||
void execute_string(const char *value);
|
||||
void close();
|
||||
|
||||
//static
|
||||
static int emu_gamename(lua_State *L);
|
||||
static int emu_keypost(lua_State *L);
|
||||
private:
|
||||
// internal state
|
||||
running_machine & m_machine; // reference to our machine
|
||||
|
@ -239,11 +239,10 @@ TIMER_CALLBACK_MEMBER(running_machine::autoboot_callback)
|
||||
m_lua_engine.execute(options().autoboot_script());
|
||||
}
|
||||
if (strlen(options().autoboot_command())!=0) {
|
||||
astring val = astring(options().autoboot_command());
|
||||
val.replace("\\n","\n");
|
||||
val.replace("\\r","\r");
|
||||
ioport().natkeyboard().post_utf8(val);
|
||||
ioport().natkeyboard().post_utf8("\r");
|
||||
astring cmd = astring(options().autoboot_command());
|
||||
cmd.replace("'","\\'");
|
||||
astring val = astring("emu.keypost('",cmd,"')");
|
||||
m_lua_engine.execute_string(val);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user