MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / ll_require

Function ll_require

extlibs/lua/src/loadlib.c:649–676  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 9

lua_settopFunction · 0.85
lua_getfieldFunction · 0.85
lua_tobooleanFunction · 0.85
findloaderFunction · 0.85
lua_pushvalueFunction · 0.85
lua_setfieldFunction · 0.85
lua_pushbooleanFunction · 0.85
lua_rotateFunction · 0.70
lua_copyFunction · 0.70

Tested by

no test coverage detected