16 const int num_args = lua_gettop(L);
23 const auto& registry = console.function_wrapper_registry_;
25 const std::string fname = lua_tostring(L, 1);
28 std::string(
"Wrapper with name \"") + fname +
29 "\" not in console registry.");
31 const auto& reg_entry = registry.at(fname);
33 auto input_params = reg_entry.get_in_params_func();
36 for (
int p = 2; p <= num_args; ++p)
38 const std::string arg_name =
"arg" + std::to_string(p-2);
40 if (lua_isboolean(L, p))
41 main_arguments_block.
AddParameter(arg_name, lua_toboolean(L, p));
42 else if (lua_isinteger(L, p))
43 main_arguments_block.
AddParameter(arg_name, lua_tointeger(L, p));
44 else if (lua_isnumber(L, p))
45 main_arguments_block.
AddParameter(arg_name, lua_tonumber(L, p));
46 else if (lua_isstring(L, p))
47 main_arguments_block.
AddParameter(arg_name, lua_tostring(L, p));
48 else if (lua_istable(L, p))
50 auto block = chi_lua::TableParserAsParameterBlock::ParseTable(L, p);
51 block.SetBlockName(arg_name);
52 std::string scope = fname +
":";
53 scope.append(arg_name +
" ");
54 block.SetErrorOriginScope(scope);
59 "\": Unsupported argument "
61 lua_typename(L, lua_type(L, p)) +
"\" encountered.");
64 input_params.SetErrorOriginScope(fname +
"()");
65 input_params.AssignParameters(main_arguments_block);
67 auto output_params = reg_entry.call_func(input_params);
69 output_params.SetErrorOriginScope(fname +
":output:");
70 chi_lua::PushParameterBlock(L, output_params);
72 const int num_sub_params =
static_cast<int>(output_params.NumParameters());
74 return output_params.IsScalar() ? 1 : num_sub_params;
#define ChiLogicalErrorIf(condition, message)
#define ChiInvalidArgument(message)
static int LuaWrapperCall(lua_State *L)
Generic entry point for wrapper calls.
static Console & GetInstance() noexcept
void AddParameter(ParameterBlock block)
RegisterLuaFunction(Console::LuaWrapperCall, chi_console, LuaWrapperCall)