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

Method InitCoreContext

library/LuaTools.cpp:2089–2124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2087}
2088
2089static void Lua::Core::InitCoreContext(color_ostream &out)
2090{
2091 auto State = DFHack::Core::getInstance().getLuaState();
2092 lua_newtable(State);
2093 lua_rawsetp(State, LUA_REGISTRYINDEX, &DFHACK_TIMEOUTS_TOKEN);
2094
2095 // Register events
2096 lua_rawgetp(State, LUA_REGISTRYINDEX, &DFHACK_DFHACK_TOKEN);
2097
2098 Event::Make(State, (void*)onStateChange);
2099 lua_setfield(State, -2, "onStateChange");
2100
2101 lua_pushcfunction(State, dfhack_timeout);
2102 lua_setfield(State, -2, "timeout");
2103 lua_pushcfunction(State, dfhack_timeout_active);
2104 lua_setfield(State, -2, "timeout_active");
2105
2106 lua_pop(State, 1);
2107
2108 if (getenv("DFHACK_ENABLE_LUACOV"))
2109 {
2110 // reads config from .luacov or uses defaults if file doesn't exist.
2111 // note that luacov overrides the debug hook installed by
2112 // interrupt_init() above.
2113 if (Lua::PushModulePublic(out, State, "luacov.runner", "init") &&
2114 Lua::SafeCall(out, State, 0, 0))
2115 {
2116 out.print("Initialized luacov coverage monitoring\n");
2117 }
2118 else
2119 {
2120 out.printerr("Failed to initialize luacov coverage monitoring\n");
2121 // non-fatal error
2122 }
2123 }
2124}
2125
2126void DFHack::Lua::Core::Reset(color_ostream &out, const char *where)
2127{

Callers

nothing calls this directly

Calls 6

lua_rawsetpFunction · 0.85
lua_rawgetpFunction · 0.85
lua_setfieldFunction · 0.85
PushModulePublicFunction · 0.85
SafeCallFunction · 0.85
printMethod · 0.45

Tested by

no test coverage detected