MCPcopy Create free account
hub / github.com/crownengine/crown / require_internal

Function require_internal

src/lua/lua_environment.cpp:208–238  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

206
207#if CROWN_DEBUG
208static int require_internal(lua_State *L)
209{
210 bool already_loaded = false;
211 const char *module_name = lua_tostring(L, 1);
212 lua_settop(L, 1);
213
214 lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
215 lua_getfield(L, -1, module_name);
216 already_loaded = lua_toboolean(L, -1);
217 lua_pop(L, 2);
218
219 lua_getglobal(L, "original_require");
220 lua_pushvalue(L, 1);
221 lua_call(L, 1, 1);
222
223 lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
224 lua_getfield(L, -1, module_name);
225 if (lua_toboolean(L, -1) && !already_loaded) {
226 lua_pop(L, 2);
227 lua_getglobal(L, "package");
228 lua_getfield(L, -1, "load_order");
229 lua_pushstring(L, module_name);
230 lua_rawseti(L, -2, int(lua_objlen(L, -2) + 1));
231 lua_pop(L, 2); // Pop "package.load_order" and "package"
232 } else {
233 lua_pop(L, 2); // Pop "_LOADED" and "_LOADED[module]"
234 }
235
236 lua_remove(L, 1);
237 return 1;
238}
239#endif // if CROWN_DEBUG
240
241LuaEnvironment::LuaEnvironment()

Callers

nothing calls this directly

Calls 9

lua_settopFunction · 0.50
lua_getfieldFunction · 0.50
lua_tobooleanFunction · 0.50
lua_pushvalueFunction · 0.50
lua_callFunction · 0.50
lua_pushstringFunction · 0.50
lua_rawsetiFunction · 0.50
lua_objlenFunction · 0.50
lua_removeFunction · 0.50

Tested by

no test coverage detected