From 431f8d361140dff4b2990a0845d8958281c90162 Mon Sep 17 00:00:00 2001 From: cracyc Date: Tue, 1 Nov 2016 19:31:19 -0500 Subject: [PATCH] luaengine: safer (nw) --- src/frontend/mame/luaengine.cpp | 2 +- src/frontend/mame/luaengine.h | 8 ++++---- src/frontend/mame/ui/mainmenu.cpp | 2 +- src/frontend/mame/ui/selgame.cpp | 4 ++-- src/frontend/mame/ui/selsoft.cpp | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/frontend/mame/luaengine.cpp b/src/frontend/mame/luaengine.cpp index 5184587e019..5f77a7a7245 100644 --- a/src/frontend/mame/luaengine.cpp +++ b/src/frontend/mame/luaengine.cpp @@ -125,7 +125,7 @@ namespace sol struct checker { template - 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(L, index, handler); } diff --git a/src/frontend/mame/luaengine.h b/src/frontend/mame/luaengine.h index a0d15fe8e45..c982837008c 100644 --- a/src/frontend/mame/luaengine.h +++ b/src/frontend/mame/luaengine.h @@ -89,15 +89,15 @@ public: 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 - 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; sol::object outobj = call_plugin(name, sol::make_object(sol(), in)); - if(outobj.is()) + if(outobj.is() && !table) ret = true; - else if(outobj.is()) + else if(outobj.is() && table) { // check just one entry, checking the whole thing shouldn't be necessary as this only supports homogeneous tables if(outobj.as().begin().operator*().second.template is()) diff --git a/src/frontend/mame/ui/mainmenu.cpp b/src/frontend/mame/ui/mainmenu.cpp index d0f0cb50d14..0b46e8fc2c7 100644 --- a/src/frontend/mame/ui/mainmenu.cpp +++ b/src/frontend/mame/ui/mainmenu.cpp @@ -130,7 +130,7 @@ void menu_main::populate() item_append(_("Plugin Options"), "", 0, (void *)PLUGINS); // add dats menu - if (mame_machine_manager::instance()->lua()->call_plugin_check("data_list", "")) + if (mame_machine_manager::instance()->lua()->call_plugin_check("data_list", "", true)) item_append(_("External DAT View"), "", 0, (void *)EXTERNAL_DATS); item_append(menu_item_type::SEPARATOR); diff --git a/src/frontend/mame/ui/selgame.cpp b/src/frontend/mame/ui/selgame.cpp index fa6d4c7ac67..9351c028a06 100644 --- a/src/frontend/mame/ui/selgame.cpp +++ b/src/frontend/mame/ui/selgame.cpp @@ -347,7 +347,7 @@ void menu_select_game::handle() if (!isfavorite()) { 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("data_list", driver->name)) + if ((uintptr_t)driver > skip_main_items && mame_machine_manager::instance()->lua()->call_plugin_check("data_list", driver->name, true)) menu::stack_push(ui(), container(), driver); } else @@ -356,7 +356,7 @@ void menu_select_game::handle() if ((uintptr_t)ui_swinfo > skip_main_items) { - if (ui_swinfo->startempty == 1 && mame_machine_manager::instance()->lua()->call_plugin_check("data_list", ui_swinfo->driver->name)) + if (ui_swinfo->startempty == 1 && mame_machine_manager::instance()->lua()->call_plugin_check("data_list", ui_swinfo->driver->name, true)) menu::stack_push(ui(), container(), ui_swinfo->driver); else if (mame_machine_manager::instance()->lua()->call_plugin_check("data_list", std::string(ui_swinfo->shortname).append(1, ',').append(ui_swinfo->listname).c_str()) || !ui_swinfo->usage.empty()) menu::stack_push(ui(), container(), ui_swinfo); diff --git a/src/frontend/mame/ui/selsoft.cpp b/src/frontend/mame/ui/selsoft.cpp index 807061887e4..8a1768afae8 100644 --- a/src/frontend/mame/ui/selsoft.cpp +++ b/src/frontend/mame/ui/selsoft.cpp @@ -247,7 +247,7 @@ void menu_select_software::handle() // handle UI_DATS ui_software_info *ui_swinfo = (ui_software_info *)menu_event->itemref; - if (ui_swinfo->startempty == 1 && mame_machine_manager::instance()->lua()->call_plugin_check("data_list", ui_swinfo->driver->name)) + if (ui_swinfo->startempty == 1 && mame_machine_manager::instance()->lua()->call_plugin_check("data_list", ui_swinfo->driver->name, true)) menu::stack_push(ui(), container(), ui_swinfo->driver); else if (mame_machine_manager::instance()->lua()->call_plugin_check("data_list", std::string(ui_swinfo->shortname).append(1, ',').append(ui_swinfo->listname).c_str()) || !ui_swinfo->usage.empty()) menu::stack_push(ui(), container(), ui_swinfo);