From e6588480c477a8132676abbbb32bfc42287d8c6d Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Wed, 23 Mar 2022 20:27:30 +1100 Subject: 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. --- src/frontend/mame/luaengine_debug.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/frontend/mame/luaengine_debug.cpp') diff --git a/src/frontend/mame/luaengine_debug.cpp b/src/frontend/mame/luaengine_debug.cpp index 94748d5a897..e2c6713ff44 100644 --- a/src/frontend/mame/luaengine_debug.cpp +++ b/src/frontend/mame/luaengine_debug.cpp @@ -181,14 +181,14 @@ void lua_engine::initialize_debug(sol::table &emu) { "m", EXPSPACE_REGION } }; - auto const do_add_symbol = [this] (symbol_table_wrapper &st, char const *name, sol::protected_function getter, std::optional setter, std::optional format) -> symbol_entry & + auto const do_add_symbol = [] (symbol_table_wrapper &st, char const *name, sol::protected_function getter, std::optional setter, std::optional format) -> symbol_entry & { symbol_table::setter_func setfun; if (setter) - setfun = [this, cbfunc = std::move(*setter)] (u64 value) { invoke(cbfunc, value); }; + setfun = [cbfunc = std::move(*setter)] (u64 value) { invoke(cbfunc, value); }; return st.table().add( name, - [this, cbfunc = std::move(getter)] () -> u64 + [cbfunc = std::move(getter)] () -> u64 { auto result = invoke(cbfunc).get >(); if (result) @@ -217,12 +217,12 @@ void lua_engine::initialize_debug(sol::table &emu) [] (device_t &device) { return std::make_shared(device.machine(), nullptr, &device); })); symbol_table_type.set_function("set_memory_modified_func", - [this] (symbol_table_wrapper &st, sol::object cb) + [] (symbol_table_wrapper &st, sol::object cb) { if (cb == sol::lua_nil) st.table().set_memory_modified_func(nullptr); else if (cb.is()) - st.table().set_memory_modified_func([this, cbfunc = cb.as()] () { invoke(cbfunc); }); + st.table().set_memory_modified_func([cbfunc = cb.as()] () { invoke(cbfunc); }); else osd_printf_error("[LUA ERROR] must call set_memory_modified_func with function or nil\n"); }); @@ -246,19 +246,19 @@ void lua_engine::initialize_debug(sol::table &emu) { return do_add_symbol(st, name, getter, std::nullopt, nullptr); }, - [this] (symbol_table_wrapper &st, char const *name, int minparams, int maxparams, sol::protected_function execute) -> symbol_entry & + [] (symbol_table_wrapper &st, sol::this_state s, char const *name, int minparams, int maxparams, sol::protected_function execute) -> symbol_entry & { return st.table().add( name, minparams, maxparams, - [this, cbref = sol::reference(execute)] (int numparams, u64 const *paramlist) -> u64 + [L = s.L, cbref = sol::reference(execute)] (int numparams, u64 const *paramlist) -> u64 { - sol::stack_reference traceback(m_lua_state, -sol::stack::push(m_lua_state, sol::default_traceback_error_handler)); + sol::stack_reference traceback(L, -sol::stack::push(L, sol::default_traceback_error_handler)); cbref.push(); - sol::stack_aligned_stack_handler_function func(m_lua_state, -1, traceback); + sol::stack_aligned_stack_handler_function func(L, -1, traceback); for (int i = 0; numparams > i; ++i) - lua_pushinteger(m_lua_state, paramlist[i]); + lua_pushinteger(L, paramlist[i]); auto result = func(sol::stack_count(numparams)).get >(); traceback.pop(); return result ? *result : 0; -- cgit v1.2.3-70-g09d2