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

Function findloader

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

Source from the content-addressed store, hash-verified

622
623
624static void findloader (lua_State *L, const char *name) {
625 int i;
626 luaL_Buffer msg; /* to build error message */
627 /* push 'package.searchers' to index 3 in the stack */
628 if (l_unlikely(lua_getfield(L, lua_upvalueindex(1), "searchers")
629 != LUA_TTABLE))
630 luaL_error(L, "'package.searchers' must be a table");
631 luaL_buffinit(L, &msg);
632 /* iterate over available searchers to find a loader */
633 for (i = 1; ; i++) {
634 luaL_addstring(&msg, "\n\t"); /* error-message prefix */
635 if (l_unlikely(lua_rawgeti(L, 3, i) == LUA_TNIL)) { /* no more searchers? */
636 lua_pop(L, 1); /* remove nil */
637 luaL_buffsub(&msg, 2); /* remove prefix */
638 luaL_pushresult(&msg); /* create error message */
639 luaL_error(L, "module '%s' not found:%s", name, lua_tostring(L, -1));
640 }
641 lua_pushstring(L, name);
642 lua_call(L, 1, 2); /* call it */
643 if (lua_isfunction(L, -2)) /* did it find a loader? */
644 return; /* module loader found */
645 else if (lua_isstring(L, -2)) { /* searcher returned error message? */
646 lua_pop(L, 1); /* remove extra return */
647 luaL_addvalue(&msg); /* concatenate error message */
648 }
649 else { /* no error message */
650 lua_pop(L, 2); /* remove both returns */
651 luaL_buffsub(&msg, 2); /* remove prefix */
652 }
653 }
654}
655
656
657static int ll_require (lua_State *L) {

Callers 1

ll_requireFunction · 0.85

Calls 9

lua_getfieldFunction · 0.85
luaL_errorFunction · 0.85
luaL_buffinitFunction · 0.85
luaL_addstringFunction · 0.85
lua_rawgetiFunction · 0.85
luaL_pushresultFunction · 0.85
lua_pushstringFunction · 0.85
lua_isstringFunction · 0.85
luaL_addvalueFunction · 0.85

Tested by

no test coverage detected