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

Function findloader

lib/lua/src/loadlib.c:615–645  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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