From eea3b08dd2ff9d0e0fbe8eeeace4a8f43af907af Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Mon, 30 Aug 2021 05:02:10 +0200 Subject: [PATCH] Add these methods --- src/game/scripting/lua/context.cpp | 65 ++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/game/scripting/lua/context.cpp b/src/game/scripting/lua/context.cpp index 947d2f70..e5a4ec30 100644 --- a/src/game/scripting/lua/context.cpp +++ b/src/game/scripting/lua/context.cpp @@ -443,6 +443,71 @@ namespace scripting::lua return functions; }; + + game_type["include"] = [](const game&, const sol::this_state s, + const std::string& filename) + { + sol::state_view state = s; + + if (scripting::script_function_table.find(filename) == scripting::script_function_table.end()) + { + throw std::runtime_error("File '" + filename + "' not found"); + } + + for (const auto& function : scripting::script_function_table[filename]) + { + const auto name = utils::string::to_lower(function.first); + + state["game_"][name] = [filename, function](const game&, const sol::this_state s, + sol::variadic_args va) + { + std::vector arguments{}; + + for (auto arg : va) + { + arguments.push_back(convert({ s, arg })); + } + + notifies::hook_enabled = false; + const auto result = convert(s, call_script_function(*::game::levelEntityId, filename, function.first, arguments)); + notifies::hook_enabled = true; + }; + + state["entity"][name] = [filename, function](const entity& entity, const sol::this_state s, + sol::variadic_args va) + { + std::vector arguments{}; + + for (auto arg : va) + { + arguments.push_back(convert({ s, arg })); + } + + notifies::hook_enabled = false; + const auto result = convert(s, call_script_function(entity, filename, function.first, arguments)); + notifies::hook_enabled = true; + }; + } + }; + + game_type["scriptcall"] = [](const game&, const sol::this_state s, const std::string& filename, + const std::string function, sol::variadic_args va) + { + std::vector arguments{}; + + for (auto arg : va) + { + arguments.push_back(convert({ s, arg })); + } + + const auto level = entity{*::game::levelEntityId}; + + notifies::hook_enabled = false; + const auto result = convert(s, call_script_function(level, filename, function, arguments)); + notifies::hook_enabled = true; + + return result; + }; } }