diff options
author | npwoods <npwoods@mess.org> | 2019-08-18 10:47:07 -0400 |
---|---|---|
committer | cracyc <cracyc@users.noreply.github.com> | 2019-08-18 09:47:07 -0500 |
commit | 47447da16bc8b6ac0a69b2f51284d27aeb1ddc60 (patch) | |
tree | e20ba46d55fe8cf494f43b0c4de0e5135b3c72ee | |
parent | d7dce40b4ac2c8d6d65c40dc0b54614d2bb729fd (diff) |
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<input_seq>.
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.
-rw-r--r-- | src/frontend/mame/luaengine.cpp | 51 |
1 files 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<input_item_class> - { - template <typename Handler> - static bool check (lua_State* L, int index, Handler&& handler, record& tracking) - { - return stack::check<const std::string &>(L, index, handler); - } - }; - template <> - struct getter<input_item_class> - { - static input_item_class get(lua_State* L, int index, record& tracking) - { - const std::string item_class = stack::get<const std::string &>(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<sol::buffer *> { static int push(lua_State* L, sol::buffer *buff) @@ -2052,12 +2025,24 @@ void lua_engine::initialize() "seq_pressed", [](input_manager &input, sol::user<input_seq> seq) { return input.seq_pressed(seq); }, "seq_to_tokens", [](input_manager &input, sol::user<input_seq> seq) { return input.seq_to_tokens(seq); }, "seq_name", [](input_manager &input, sol::user<input_seq> 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<sol::user<input_seq>>()) - start = &seq.as<sol::user<input_seq>>(); - 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<sol::user<input_seq>>()) + start = &seq.as<sol::user<input_seq>>(); + 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) |