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

Function ll_require

depends/lua/src/loadlib.c:597–618  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

595
596
597static int ll_require (lua_State *L) {
598 const char *name = luaL_checkstring(L, 1);
599 lua_settop(L, 1); /* LOADED table will be at index 2 */
600 lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);
601 lua_getfield(L, 2, name); /* LOADED[name] */
602 if (lua_toboolean(L, -1)) /* is it there? */
603 return 1; /* package is already loaded */
604 /* else must load package */
605 lua_pop(L, 1); /* remove 'getfield' result */
606 findloader(L, name);
607 lua_pushstring(L, name); /* pass name as argument to module loader */
608 lua_insert(L, -2); /* name is 1st argument (before search data) */
609 lua_call(L, 2, 1); /* run loader to load module */
610 if (!lua_isnil(L, -1)) /* non-nil return? */
611 lua_setfield(L, 2, name); /* LOADED[name] = returned value */
612 if (lua_getfield(L, 2, name) == LUA_TNIL) { /* module set no value? */
613 lua_pushboolean(L, 1); /* use true as result */
614 lua_pushvalue(L, -1); /* extra copy to be returned */
615 lua_setfield(L, 2, name); /* LOADED[name] = true */
616 }
617 return 1;
618}
619
620/* }====================================================== */
621

Callers

nothing calls this directly

Calls 8

lua_settopFunction · 0.85
lua_getfieldFunction · 0.85
lua_tobooleanFunction · 0.85
findloaderFunction · 0.85
lua_pushstringFunction · 0.85
lua_setfieldFunction · 0.85
lua_pushbooleanFunction · 0.85
lua_pushvalueFunction · 0.85

Tested by

no test coverage detected