MCPcopy Create free account
hub / github.com/DFHack/dfhack / findloader

Function findloader

depends/lua/src/loadlib.c:569–594  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

567
568
569static void findloader (lua_State *L, const char *name) {
570 int i;
571 luaL_Buffer msg; /* to build error message */
572 luaL_buffinit(L, &msg);
573 /* push 'package.searchers' to index 3 in the stack */
574 if (lua_getfield(L, lua_upvalueindex(1), "searchers") != LUA_TTABLE)
575 luaL_error(L, "'package.searchers' must be a table");
576 /* iterate over available searchers to find a loader */
577 for (i = 1; ; i++) {
578 if (lua_rawgeti(L, 3, i) == LUA_TNIL) { /* no more searchers? */
579 lua_pop(L, 1); /* remove nil */
580 luaL_pushresult(&msg); /* create error message */
581 luaL_error(L, "module '%s' not found:%s", name, lua_tostring(L, -1));
582 }
583 lua_pushstring(L, name);
584 lua_call(L, 1, 2); /* call it */
585 if (lua_isfunction(L, -2)) /* did it find a loader? */
586 return; /* module loader found */
587 else if (lua_isstring(L, -2)) { /* searcher returned error message? */
588 lua_pop(L, 1); /* remove extra return */
589 luaL_addvalue(&msg); /* concatenate error message */
590 }
591 else
592 lua_pop(L, 2); /* remove both returns */
593 }
594}
595
596
597static int ll_require (lua_State *L) {

Callers 1

ll_requireFunction · 0.85

Calls 8

luaL_buffinitFunction · 0.85
lua_getfieldFunction · 0.85
luaL_errorFunction · 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