| 585 | |
| 586 | |
| 587 | static void findloader(lua_State *L, const char *name) { |
| 588 | int i; |
| 589 | luaL_Buffer msg; /* to build error message */ |
| 590 | luaL_buffinit(L, &msg); |
| 591 | /* push 'package.searchers' to index 3 in the stack */ |
| 592 | if (lua_getfield(L, lua_upvalueindex(1), "searchers") != LUA_TTABLE) |
| 593 | luaL_error(L, "'package.searchers' must be a table"); |
| 594 | /* iterate over available searchers to find a loader */ |
| 595 | for (i = 1;; i++) { |
| 596 | if (lua_rawgeti(L, 3, i) == LUA_TNIL) { /* no more searchers? */ |
| 597 | lua_pop(L, 1); /* remove nil */ |
| 598 | luaL_pushresult(&msg); /* create error message */ |
| 599 | luaL_error(L, "module '%s' not found:%s", name, lua_tostring(L, -1)); |
| 600 | } |
| 601 | lua_pushstring(L, name); |
| 602 | lua_call(L, 1, 2); /* call it */ |
| 603 | if (lua_isfunction(L, -2)) /* did it find a loader? */ |
| 604 | return; /* module loader found */ |
| 605 | else if (lua_isstring(L, -2)) { /* searcher returned error message? */ |
| 606 | lua_pop(L, 1); /* remove extra return */ |
| 607 | luaL_addvalue(&msg); /* concatenate error message */ |
| 608 | } |
| 609 | else |
| 610 | lua_pop(L, 2); /* remove both returns */ |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | static void findloader_for_import_contract(lua_State *L, const char *name) |
| 615 | { |
nothing calls this directly
no test coverage detected