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

Function ll_require

third-party/lua-5.2.4/src/loadlib.c:508–530  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

506
507
508static int ll_require (lua_State *L) {
509 const char *name = luaL_checkstring(L, 1);
510 lua_settop(L, 1); /* _LOADED table will be at index 2 */
511 lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
512 lua_getfield(L, 2, name); /* _LOADED[name] */
513 if (lua_toboolean(L, -1)) /* is it there? */
514 return 1; /* package is already loaded */
515 /* else must load package */
516 lua_pop(L, 1); /* remove 'getfield' result */
517 findloader(L, name);
518 lua_pushstring(L, name); /* pass name as argument to module loader */
519 lua_insert(L, -2); /* name is 1st argument (before search data) */
520 lua_call(L, 2, 1); /* run loader to load module */
521 if (!lua_isnil(L, -1)) /* non-nil return? */
522 lua_setfield(L, 2, name); /* _LOADED[name] = returned value */
523 lua_getfield(L, 2, name);
524 if (lua_isnil(L, -1)) { /* module did not set a value? */
525 lua_pushboolean(L, 1); /* use true as result */
526 lua_pushvalue(L, -1); /* extra copy to be returned */
527 lua_setfield(L, 2, name); /* _LOADED[name] = true */
528 }
529 return 1;
530}
531
532/* }====================================================== */
533

Callers

nothing calls this directly

Calls 10

lua_settopFunction · 0.70
lua_getfieldFunction · 0.70
lua_tobooleanFunction · 0.70
findloaderFunction · 0.70
lua_pushstringFunction · 0.70
lua_insertFunction · 0.70
lua_setfieldFunction · 0.70
lua_pushbooleanFunction · 0.70
lua_pushvalueFunction · 0.70
lua_callFunction · 0.50

Tested by

no test coverage detected