From d1ea7a76ea9f211f34d2283cb2347505b3a62e50 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Fri, 8 Apr 2022 16:19:52 +0200 Subject: [PATCH] Small fix --- src/client/game/ui_scripting/lua/context.cpp | 54 +++++--------------- 1 file changed, 12 insertions(+), 42 deletions(-) diff --git a/src/client/game/ui_scripting/lua/context.cpp b/src/client/game/ui_scripting/lua/context.cpp index 0e5d831c..f38dcc19 100644 --- a/src/client/game/ui_scripting/lua/context.cpp +++ b/src/client/game/ui_scripting/lua/context.cpp @@ -30,45 +30,6 @@ namespace ui_scripting::lua { const auto json_script = utils::nt::load_resource(LUA_JSON); - scripting::script_value script_convert(const sol::lua_value& value) - { - if (value.is()) - { - return {value.as()}; - } - - if (value.is()) - { - return {value.as()}; - } - - if (value.is()) - { - return {value.as()}; - } - - if (value.is()) - { - return {value.as()}; - } - - if (value.is()) - { - return {value.as()}; - } - if (value.is()) - { - return {value.as()}; - } - - if (value.is()) - { - return {value.as()}; - } - - return {}; - } - bool valid_dvar_name(const std::string& name) { for (const auto c : name) @@ -435,15 +396,24 @@ namespace ui_scripting::lua throw std::runtime_error("Not in game"); } - ::scheduler::once([s, name, args = std::vector(va.begin(), va.end())]() + const sol::state_view view{s}; + const auto to_string = view["tostring"].get(); + + std::vector args{}; + for (auto arg : va) + { + args.push_back(to_string.call(arg).get()); + } + + ::scheduler::once([s, name, args]() { try { std::vector arguments{}; - for (auto arg : args) + for (const auto& arg : args) { - arguments.push_back(script_convert({s, arg})); + arguments.push_back(arg); } const auto player = scripting::call("getentbynum", {0}).as();