MCPcopy Create free account
hub / github.com/DFHack/dfhack / CallLuaModuleFunction

Method CallLuaModuleFunction

library/LuaTools.cpp:836–859  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

834}
835
836bool DFHack::Lua::CallLuaModuleFunction(color_ostream &out, lua_State *L,
837 const char *module_name, const char *fn_name,
838 int nargs, int nres, LuaLambda && args_lambda, LuaLambda && res_lambda,
839 bool perr){
840 Lua::StackUnwinder top(L);
841
842 if (!lua_checkstack(L, 1 + nargs) ||
843 !Lua::PushModulePublic(out, L, module_name, fn_name)) {
844 if (perr)
845 out.printerr("Failed to load {} Lua code\n", module_name);
846 return false;
847 }
848
849 std::forward<LuaLambda&&>(args_lambda)(L);
850
851 if (!Lua::SafeCall(out, L, nargs, nres, perr)) {
852 if (perr)
853 out.printerr("Failed Lua call to '{}.{}'\n", module_name, fn_name);
854 return false;
855 }
856
857 std::forward<LuaLambda&&>(res_lambda)(L);
858 return true;
859}
860
861// Copied from lcorolib.c, with error handling modifications
862static int resume_helper(lua_State *L, lua_State *co, int narg, int nres)

Callers

nothing calls this directly

Calls 3

lua_checkstackFunction · 0.85
PushModulePublicFunction · 0.85
SafeCallFunction · 0.85

Tested by

no test coverage detected