MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / ll_require

Function ll_require

lib/lua/src/loadlib.c:648–675  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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