mirror of
https://github.com/holub/mame
synced 2025-05-29 17:13:05 +03: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
|
// 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);
|
lua_pushstring(L, luaThis->machine().system().description);
|
||||||
return 1;
|
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 [] =
|
static const struct luaL_Reg emu_funcs [] =
|
||||||
{
|
{
|
||||||
{ "gamename", lua_engine::emu_gamename },
|
{ "gamename", lua_engine::emu_gamename },
|
||||||
|
{ "keypost", lua_engine::emu_keypost },
|
||||||
{ NULL, NULL } /* sentinel */
|
{ 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();
|
close();
|
||||||
|
|
||||||
@ -155,13 +167,35 @@ void lua_engine::execute(const char *filename)
|
|||||||
luaL_openlibs(m_lua_state);
|
luaL_openlibs(m_lua_state);
|
||||||
luaL_requiref(m_lua_state, "emu", luaopen_emu, 1);
|
luaL_requiref(m_lua_state, "emu", luaopen_emu, 1);
|
||||||
lua_sethook(m_lua_state, hook, LUA_MASKLINE, 0);
|
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);
|
int s = luaL_loadfile(m_lua_state, filename);
|
||||||
report_errors(s);
|
report_errors(s);
|
||||||
|
|
||||||
mame_printf_verbose("[LUA] Start executing script\n");
|
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
|
// lua_execute - execute slice of lua script
|
||||||
// this callback is hooked to frame notification
|
// this callback is hooked to frame notification
|
||||||
|
@ -62,12 +62,14 @@ public:
|
|||||||
void lua_execute();
|
void lua_execute();
|
||||||
void report_errors(int status);
|
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();
|
void close();
|
||||||
|
|
||||||
//static
|
//static
|
||||||
static int emu_gamename(lua_State *L);
|
static int emu_gamename(lua_State *L);
|
||||||
|
static int emu_keypost(lua_State *L);
|
||||||
private:
|
private:
|
||||||
// internal state
|
// internal state
|
||||||
running_machine & m_machine; // reference to our machine
|
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());
|
m_lua_engine.execute(options().autoboot_script());
|
||||||
}
|
}
|
||||||
if (strlen(options().autoboot_command())!=0) {
|
if (strlen(options().autoboot_command())!=0) {
|
||||||
astring val = astring(options().autoboot_command());
|
astring cmd = astring(options().autoboot_command());
|
||||||
val.replace("\\n","\n");
|
cmd.replace("'","\\'");
|
||||||
val.replace("\\r","\r");
|
astring val = astring("emu.keypost('",cmd,"')");
|
||||||
ioport().natkeyboard().post_utf8(val);
|
m_lua_engine.execute_string(val);
|
||||||
ioport().natkeyboard().post_utf8("\r");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user