diff options
author | 2022-03-23 20:27:30 +1100 | |
---|---|---|
committer | 2022-03-23 20:27:30 +1100 | |
commit | e6588480c477a8132676abbbb32bfc42287d8c6d (patch) | |
tree | b483f8b9e049a280f68ae7b0af9c57372676f5df /src/frontend/mame/luaengine.h | |
parent | bb3f3e5abd7051ed371fe7fbdd0f49a56cc03f1f (diff) |
Lua engine improvements (#9453)
Made auto-boot script errors and plugin bootstrap errors fatal.
Run auto-boot scripts in a sandbox. Globals can be accessed, but not
set. The sandbox is cleared on hard reset, but not on soft reset.
Added (hopefully) useful to string metafunctions to device_t and
address space that show short names and tags.
Fixed issues in plugins that surface when strict type checking is
enabled, as this means numbers and nil are not automatically converted
to strings. Plugins should be tested with debug builds to check for
this.
Made save item read_block raise an error on invalid arguments rather
than returning an empty string, and made it use luaL_buffer directly
rather than using the helper wrapper.
Changed some more function bindings to use set_function to avoid issues
related to ThePhD/sol2#608, and got rid of some unnecessary lambda
captures.
Diffstat (limited to 'src/frontend/mame/luaengine.h')
-rw-r--r-- | src/frontend/mame/luaengine.h | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/frontend/mame/luaengine.h b/src/frontend/mame/luaengine.h index 6c5f572885d..27761eb85b5 100644 --- a/src/frontend/mame/luaengine.h +++ b/src/frontend/mame/luaengine.h @@ -34,7 +34,6 @@ class lua_engine { public: // helper structures - class buffer_helper; template <typename T> struct devenum; template <typename T> struct simple_list_wrapper; template <typename T> struct tag_object_ptr_map; @@ -48,8 +47,9 @@ public: ~lua_engine(); void initialize(); - void load_script(const char *filename); - void load_string(const char *value); + sol::load_result load_script(std::string const &filename); + sol::load_result load_string(std::string const &value); + sol::environment make_environment(); bool frame_hook(); @@ -122,9 +122,27 @@ public: sol::state_view &sol() const { return *m_sol_state; } + template <typename Func, typename... Params> + static std::decay_t<std::invoke_result_t<Func, Params...> > invoke(Func &&func, Params&&... args) + { + g_profiler.start(PROFILER_LUA); + try + { + auto result = func(std::forward<Params>(args)...); + g_profiler.stop(); + return result; + } + catch (...) + { + g_profiler.stop(); + throw; + } + } + private: - template<typename T, size_t SIZE> class enum_parser; + template <typename T, size_t Size> class enum_parser; + class buffer_helper; struct addr_space; class tap_helper; class addr_space_change_notif; @@ -170,17 +188,12 @@ private: void resume(int nparam); void register_function(sol::function func, const char *id); - int enumerate_functions(const char *id, std::function<bool(const sol::protected_function &func)> &&callback); + template <typename T> size_t enumerate_functions(const char *id, T &&callback); bool execute_function(const char *id); sol::object call_plugin(const std::string &name, sol::object in); void close(); - void run(sol::load_result res); - - template <typename TFunc, typename... TArgs> - sol::protected_function_result invoke(TFunc &&func, TArgs&&... args); - void initialize_debug(sol::table &emu); void initialize_input(sol::table &emu); void initialize_memory(sol::table &emu); |