| 834 | } |
| 835 | |
| 836 | bool 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 |
| 862 | static int resume_helper(lua_State *L, lua_State *co, int narg, int nres) |
nothing calls this directly
no test coverage detected