MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / ll_require

Function ll_require

3rd/lua-5.4.3/src/loadlib.c:657–684  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected