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

Method SafeCallString

library/LuaTools.cpp:1139–1174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1137}
1138
1139bool DFHack::Lua::SafeCallString(color_ostream &out, lua_State *state, const std::string &code,
1140 int nargs, int nres, bool perr,
1141 const char *debug_tag, int env_idx)
1142{
1143 AssertCoreSuspend(state);
1144
1145 if (!debug_tag)
1146 debug_tag = code.c_str();
1147 if (env_idx)
1148 env_idx = lua_absindex(state, env_idx);
1149
1150 int base = lua_gettop(state);
1151 (void)base; // used in assert()
1152
1153 // Parse the code
1154 if (luaL_loadbuffer(state, code.data(), code.size(), debug_tag) != LUA_OK)
1155 {
1156 if (perr)
1157 report_error(state, &out, true);
1158
1159 return false;
1160 }
1161
1162 // Replace _ENV
1163 if (env_idx)
1164 {
1165 lua_pushvalue(state, env_idx);
1166 lua_setupvalue(state, -2, 1);
1167 assert(lua_gettop(state) == base+1);
1168 }
1169
1170 if (nargs > 0)
1171 lua_insert(state, -1-nargs);
1172
1173 return Lua::SafeCall(out, state, nargs, nres, perr);
1174}
1175
1176/*
1177 * Coroutine interactive query loop

Callers

nothing calls this directly

Calls 10

AssertCoreSuspendFunction · 0.85
lua_absindexFunction · 0.85
lua_gettopFunction · 0.85
report_errorFunction · 0.85
lua_pushvalueFunction · 0.85
lua_setupvalueFunction · 0.85
SafeCallFunction · 0.85
c_strMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected