MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / ll_require

Function ll_require

third-party/lua-5.5.0/src/loadlib.c:650–677  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

648
649
650static int ll_require (lua_State *L) {
651 const char *name = luaL_checkstring(L, 1);
652 lua_settop(L, 1); /* LOADED table will be at index 2 */
653 lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);
654 lua_getfield(L, 2, name); /* LOADED[name] */
655 if (lua_toboolean(L, -1)) /* is it there? */
656 return 1; /* package is already loaded */
657 /* else must load package */
658 lua_pop(L, 1); /* remove 'getfield' result */
659 findloader(L, name);
660 lua_rotate(L, -2, 1); /* function <-> loader data */
661 lua_pushvalue(L, 1); /* name is 1st argument to module loader */
662 lua_pushvalue(L, -3); /* loader data is 2nd argument */
663 /* stack: ...; loader data; loader function; mod. name; loader data */
664 lua_call(L, 2, 1); /* run loader to load module */
665 /* stack: ...; loader data; result from loader */
666 if (!lua_isnil(L, -1)) /* non-nil return? */
667 lua_setfield(L, 2, name); /* LOADED[name] = returned value */
668 else
669 lua_pop(L, 1); /* pop nil */
670 if (lua_getfield(L, 2, name) == LUA_TNIL) { /* module set no value? */
671 lua_pushboolean(L, 1); /* use true as result */
672 lua_copy(L, -1, -2); /* replace loader result */
673 lua_setfield(L, 2, name); /* LOADED[name] = true */
674 }
675 lua_rotate(L, -2, 1); /* loader data <-> module result */
676 return 2; /* return module result and loader data */
677}
678
679/* }====================================================== */
680

Callers

nothing calls this directly

Calls 10

lua_settopFunction · 0.70
lua_getfieldFunction · 0.70
lua_tobooleanFunction · 0.70
findloaderFunction · 0.70
lua_rotateFunction · 0.70
lua_pushvalueFunction · 0.70
lua_setfieldFunction · 0.70
lua_pushbooleanFunction · 0.70
lua_copyFunction · 0.70
lua_callFunction · 0.50

Tested by

no test coverage detected