Merge branch 'develop'

This commit is contained in:
Federico Cecchetto 2022-05-01 17:54:32 +02:00
commit b495b8fd04
3 changed files with 27 additions and 11 deletions

View File

@ -182,11 +182,6 @@ namespace ui_scripting
auto game_type = game(); auto game_type = game();
lua["game"] = game_type; lua["game"] = game_type;
game_type["addlocalizedstring"] = [](const game&, const std::string& a, const std::string& b)
{
localized_strings::override(a, b);
};
game_type["sharedset"] = [](const game&, const std::string& key, const std::string& value) game_type["sharedset"] = [](const game&, const std::string& key, const std::string& value)
{ {
scripting::shared_table.access([key, value](scripting::shared_table_t& table) scripting::shared_table.access([key, value](scripting::shared_table_t& table)
@ -281,7 +276,9 @@ namespace ui_scripting
std::vector<std::string> args{}; std::vector<std::string> args{};
for (const auto& value : va) for (const auto& value : va)
{ {
args.push_back(to_string(value)[0].as<std::string>()); const auto value_str = to_string(value);
args.push_back(value_str[0].as<std::string>());
} }
::scheduler::once([name, args]() ::scheduler::once([name, args]()

View File

@ -78,6 +78,26 @@ namespace ui_scripting
return values; return values;
} }
arguments get_return_values(game::hks::HksObject* base)
{
const auto state = *game::hks::lua_state;
const auto count = static_cast<int>(state->m_apistack.top - base);
arguments values;
for (auto i = count - 1; i >= 0; i--)
{
const auto v = get_return_value(i);
values.push_back(v);
}
if (values.size() == 0)
{
values.push_back({});
}
return values;
}
bool notify(const std::string& name, const event_arguments& arguments) bool notify(const std::string& name, const event_arguments& arguments)
{ {
const auto state = *game::hks::lua_state; const auto state = *game::hks::lua_state;
@ -127,10 +147,8 @@ namespace ui_scripting
push_value(*i); push_value(*i);
} }
const auto num_args = static_cast<int>(arguments.size()); game::hks::vm_call_internal(state, static_cast<int>(arguments.size()), -1, 0);
const auto args = get_return_values(top);
game::hks::vm_call_internal(state, num_args, -1, 0);
const auto args = get_return_values();
state->m_apistack.top = top; state->m_apistack.top = top;
return args; return args;
} }

View File

@ -10,6 +10,7 @@ namespace ui_scripting
script_value get_return_value(int offset); script_value get_return_value(int offset);
arguments get_return_values(); arguments get_return_values();
arguments get_return_values(game::hks::HksObject* base);
bool notify(const std::string& name, const event_arguments& arguments); bool notify(const std::string& name, const event_arguments& arguments);