diff --git a/src/frontend/mame/luaengine.cpp b/src/frontend/mame/luaengine.cpp index 34d9c769338..a1ecf792d8e 100644 --- a/src/frontend/mame/luaengine.cpp +++ b/src/frontend/mame/luaengine.cpp @@ -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("file", sol::call_constructor, sol::constructors>(), "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(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()) diff --git a/src/frontend/mame/luaengine.h b/src/frontend/mame/luaengine.h index b03fabb1f8b..dfc860f21e5 100644 --- a/src/frontend/mame/luaengine.h +++ b/src/frontend/mame/luaengine.h @@ -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);