mirror of
https://github.com/mamedev/mame.git
synced 2024-11-16 07:48:32 +01:00
luaengine: wait (nw)
This commit is contained in:
parent
c2a81dfca7
commit
74f6ea68e4
2 changed files with 18 additions and 0 deletions
|
@ -769,6 +769,12 @@ void lua_engine::initialize()
|
|||
return sol::make_object(sol(), sol::nil);
|
||||
return sol::make_object(sol(), driver_list::driver(i));
|
||||
};
|
||||
emu["wait"] = lua_CFunction([](lua_State *L) {
|
||||
lua_engine *engine = mame_machine_manager::instance()->lua();
|
||||
luaL_argcheck(L, lua_isnumber(L, 1), 1, "waiting duration expected");
|
||||
engine->machine().scheduler().timer_set(attotime::from_double(lua_tonumber(L, 1)), timer_expired_delegate(FUNC(lua_engine::resume), engine), 0, L);
|
||||
return lua_yield(L, 0);
|
||||
});
|
||||
|
||||
emu.new_usertype<emu_file>("file", sol::call_constructor, sol::constructors<sol::types<const char *, uint32_t>>(),
|
||||
"read", [](emu_file &file, sol::buffer *buff) { buff->set_len(file.read(buff->get_ptr(), buff->get_len())); return buff; },
|
||||
|
@ -1709,6 +1715,17 @@ void lua_engine::close()
|
|||
lua_close(m_lua_state);
|
||||
}
|
||||
|
||||
void lua_engine::resume(void *ptr, int nparam)
|
||||
{
|
||||
lua_State *L = static_cast<lua_State *>(ptr);
|
||||
int stat = lua_resume(L, nullptr, 0);
|
||||
if((stat != LUA_OK) && (stat != LUA_YIELD))
|
||||
{
|
||||
osd_printf_error("[LUA ERROR] in resume: %s\n", lua_tostring(L, -1));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void lua_engine::run(sol::load_result res)
|
||||
{
|
||||
if(res.valid())
|
||||
|
|
|
@ -120,6 +120,7 @@ private:
|
|||
void on_machine_resume();
|
||||
void on_machine_frame();
|
||||
|
||||
void resume(void *ptr, int nparam);
|
||||
void register_function(sol::function func, const char *id);
|
||||
bool execute_function(const char *id);
|
||||
sol::object call_plugin(const std::string &name, sol::object in);
|
||||
|
|
Loading…
Reference in a new issue