luaengine: safer (nw)

This commit is contained in:
cracyc 2016-11-01 19:31:19 -05:00
parent 06363cf65a
commit 431f8d3611
5 changed files with 9 additions and 9 deletions

View File

@ -125,7 +125,7 @@ namespace sol
struct checker<sol::buffer *> struct checker<sol::buffer *>
{ {
template <typename Handler> template <typename Handler>
static bool check ( lua_State* L, int index, Handler&& handler, record& tracking ) static bool check (lua_State* L, int index, Handler&& handler, record& tracking)
{ {
return stack::check<int>(L, index, handler); return stack::check<int>(L, index, handler);
} }

View File

@ -89,15 +89,15 @@ public:
return ret; return ret;
} }
// this will also check if a returned table contains type T // this can also check if a returned table contains type T
template<typename T, typename U> template<typename T, typename U>
bool call_plugin_check(const std::string &name, const U in) bool call_plugin_check(const std::string &name, const U in, bool table = false)
{ {
bool ret = false; bool ret = false;
sol::object outobj = call_plugin(name, sol::make_object(sol(), in)); sol::object outobj = call_plugin(name, sol::make_object(sol(), in));
if(outobj.is<T>()) if(outobj.is<T>() && !table)
ret = true; ret = true;
else if(outobj.is<sol::table>()) else if(outobj.is<sol::table>() && table)
{ {
// check just one entry, checking the whole thing shouldn't be necessary as this only supports homogeneous tables // check just one entry, checking the whole thing shouldn't be necessary as this only supports homogeneous tables
if(outobj.as<sol::table>().begin().operator*().second.template is<T>()) if(outobj.as<sol::table>().begin().operator*().second.template is<T>())

View File

@ -130,7 +130,7 @@ void menu_main::populate()
item_append(_("Plugin Options"), "", 0, (void *)PLUGINS); item_append(_("Plugin Options"), "", 0, (void *)PLUGINS);
// add dats menu // add dats menu
if (mame_machine_manager::instance()->lua()->call_plugin_check<const char *>("data_list", "")) if (mame_machine_manager::instance()->lua()->call_plugin_check<const char *>("data_list", "", true))
item_append(_("External DAT View"), "", 0, (void *)EXTERNAL_DATS); item_append(_("External DAT View"), "", 0, (void *)EXTERNAL_DATS);
item_append(menu_item_type::SEPARATOR); item_append(menu_item_type::SEPARATOR);

View File

@ -347,7 +347,7 @@ void menu_select_game::handle()
if (!isfavorite()) if (!isfavorite())
{ {
const game_driver *driver = (const game_driver *)menu_event->itemref; const game_driver *driver = (const game_driver *)menu_event->itemref;
if ((uintptr_t)driver > skip_main_items && mame_machine_manager::instance()->lua()->call_plugin_check<const char *>("data_list", driver->name)) if ((uintptr_t)driver > skip_main_items && mame_machine_manager::instance()->lua()->call_plugin_check<const char *>("data_list", driver->name, true))
menu::stack_push<menu_dats_view>(ui(), container(), driver); menu::stack_push<menu_dats_view>(ui(), container(), driver);
} }
else else
@ -356,7 +356,7 @@ void menu_select_game::handle()
if ((uintptr_t)ui_swinfo > skip_main_items) if ((uintptr_t)ui_swinfo > skip_main_items)
{ {
if (ui_swinfo->startempty == 1 && mame_machine_manager::instance()->lua()->call_plugin_check<const char *>("data_list", ui_swinfo->driver->name)) if (ui_swinfo->startempty == 1 && mame_machine_manager::instance()->lua()->call_plugin_check<const char *>("data_list", ui_swinfo->driver->name, true))
menu::stack_push<menu_dats_view>(ui(), container(), ui_swinfo->driver); menu::stack_push<menu_dats_view>(ui(), container(), ui_swinfo->driver);
else if (mame_machine_manager::instance()->lua()->call_plugin_check<const char *>("data_list", std::string(ui_swinfo->shortname).append(1, ',').append(ui_swinfo->listname).c_str()) || !ui_swinfo->usage.empty()) else if (mame_machine_manager::instance()->lua()->call_plugin_check<const char *>("data_list", std::string(ui_swinfo->shortname).append(1, ',').append(ui_swinfo->listname).c_str()) || !ui_swinfo->usage.empty())
menu::stack_push<menu_dats_view>(ui(), container(), ui_swinfo); menu::stack_push<menu_dats_view>(ui(), container(), ui_swinfo);

View File

@ -247,7 +247,7 @@ void menu_select_software::handle()
// handle UI_DATS // handle UI_DATS
ui_software_info *ui_swinfo = (ui_software_info *)menu_event->itemref; ui_software_info *ui_swinfo = (ui_software_info *)menu_event->itemref;
if (ui_swinfo->startempty == 1 && mame_machine_manager::instance()->lua()->call_plugin_check<const char *>("data_list", ui_swinfo->driver->name)) if (ui_swinfo->startempty == 1 && mame_machine_manager::instance()->lua()->call_plugin_check<const char *>("data_list", ui_swinfo->driver->name, true))
menu::stack_push<menu_dats_view>(ui(), container(), ui_swinfo->driver); menu::stack_push<menu_dats_view>(ui(), container(), ui_swinfo->driver);
else if (mame_machine_manager::instance()->lua()->call_plugin_check<const char *>("data_list", std::string(ui_swinfo->shortname).append(1, ',').append(ui_swinfo->listname).c_str()) || !ui_swinfo->usage.empty()) else if (mame_machine_manager::instance()->lua()->call_plugin_check<const char *>("data_list", std::string(ui_swinfo->shortname).append(1, ',').append(ui_swinfo->listname).c_str()) || !ui_swinfo->usage.empty())
menu::stack_push<menu_dats_view>(ui(), container(), ui_swinfo); menu::stack_push<menu_dats_view>(ui(), container(), ui_swinfo);