From 47447da16bc8b6ac0a69b2f51284d27aeb1ddc60 Mon Sep 17 00:00:00 2001 From: npwoods Date: Sun, 18 Aug 2019 10:47:07 -0400 Subject: [PATCH] Changes LUA seq_poll_start to take the input_item_class as a string (#5503) This seems to work around a problem that (at least for me) caused the 'sol::object seq' parameter to not properly handle a specified sol::user. This problem could be reproduced with the following command at the LUA console: manager:machine():input():seq_poll_start("absolute", manager:machine():input():seq_from_tokens("KEYCODE_Q")) I would feel more comfortable if I understood why the existing code failed; it isn't clear to me if this is a bug in our sol handling for input_item_class, a bug in sol itself, or a compiler bug, but this change works for me and should definitely not introduce any problems. --- src/frontend/mame/luaengine.cpp | 51 ++++++++++++--------------------- 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/src/frontend/mame/luaengine.cpp b/src/frontend/mame/luaengine.cpp index 2f8e8a66582..23956fc466d 100644 --- a/src/frontend/mame/luaengine.cpp +++ b/src/frontend/mame/luaengine.cpp @@ -145,33 +145,6 @@ namespace sol } }; template <> - struct checker - { - template - static bool check (lua_State* L, int index, Handler&& handler, record& tracking) - { - return stack::check(L, index, handler); - } - }; - template <> - struct getter - { - static input_item_class get(lua_State* L, int index, record& tracking) - { - const std::string item_class = stack::get(L, index); - if(item_class == "switch") - return ITEM_CLASS_SWITCH; - else if(item_class == "absolute" || item_class == "abs") - return ITEM_CLASS_ABSOLUTE; - else if(item_class == "relative" || item_class == "rel") - return ITEM_CLASS_RELATIVE; - else if(item_class == "maximum" || item_class == "max") - return ITEM_CLASS_MAXIMUM; - else - return ITEM_CLASS_INVALID; - } - }; - template <> struct pusher { static int push(lua_State* L, sol::buffer *buff) @@ -2052,12 +2025,24 @@ void lua_engine::initialize() "seq_pressed", [](input_manager &input, sol::user seq) { return input.seq_pressed(seq); }, "seq_to_tokens", [](input_manager &input, sol::user seq) { return input.seq_to_tokens(seq); }, "seq_name", [](input_manager &input, sol::user seq) { return input.seq_name(seq); }, - "seq_poll_start", [](input_manager &input, input_item_class cls, sol::object seq) { - input_seq *start = nullptr; - if(seq.is>()) - start = &seq.as>(); - input.seq_poll_start(cls, start); - }, + "seq_poll_start", [](input_manager &input, const char *cls_string, sol::object seq) { + input_item_class cls; + if (!strcmp(cls_string, "switch")) + cls = ITEM_CLASS_SWITCH; + else if (!strcmp(cls_string, "absolute") || !strcmp(cls_string, "abs")) + cls = ITEM_CLASS_ABSOLUTE; + else if (!strcmp(cls_string, "relative") || !strcmp(cls_string, "rel")) + cls = ITEM_CLASS_RELATIVE; + else if (!strcmp(cls_string, "maximum") || !strcmp(cls_string, "max")) + cls = ITEM_CLASS_MAXIMUM; + else + cls = ITEM_CLASS_INVALID; + + input_seq *start = nullptr; + if(seq.is>()) + start = &seq.as>(); + input.seq_poll_start(cls, start); + }, "seq_poll", &input_manager::seq_poll, "seq_poll_final", [](input_manager &input) { return sol::make_user(input.seq_poll_final()); }, "device_classes", sol::property([this](input_manager &input)