MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / findloader

Function findloader

libraries/AP_Scripting/lua/src/loadlib.c:575–619  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

573#endif
574
575static void findloader (lua_State *L, const char *name) {
576 luaL_Buffer msg; /* to build error message */
577 luaL_buffinit(L, &msg);
578 lua_pushstring(L, name);
579#if defined(ARDUPILOT_BUILD)
580 // since we only use lua modules there's no point
581 // in searching for C or other types of modules
582 // so we just call the lua searcher
583 searcher_Lua(L);
584 if (lua_isfunction(L, -2)) { /* module loader found? */
585 return; /* module loader already on stack */
586 } else if (lua_isstring(L, -2)) { /* searcher returned error message? */
587 lua_pop(L, 1); /* remove extra return */
588 luaL_addvalue(&msg); /* concatenate error message */
589 } else {
590 lua_pop(L, 2); /* remove both returns */
591 }
592 // module not found
593 lua_pop(L, 1); /* remove nil */
594 luaL_pushresult(&msg); /* create error message */
595 luaL_error(L, "module '%s' not found:%s", name, lua_tostring(L, -1));
596#else
597 /* push 'package.searchers' to index 3 in the stack */
598 if (lua_getfield(L, lua_upvalueindex(1), "searchers") != LUA_TTABLE)
599 luaL_error(L, "'package.searchers' must be a table");
600 /* iterate over available searchers to find a loader */
601 for (i = 1; ; i++) {
602 if (lua_rawgeti(L, 3, i) == LUA_TNIL) { /* no more searchers? */
603 lua_pop(L, 1); /* remove nil */
604 luaL_pushresult(&msg); /* create error message */
605 luaL_error(L, "module '%s' not found:%s", name, lua_tostring(L, -1));
606 }
607 lua_pushstring(L, name);
608 lua_call(L, 1, 2); /* call it */
609 if (lua_isfunction(L, -2)) /* did it find a loader? */
610 return; /* module loader found */
611 else if (lua_isstring(L, -2)) { /* searcher returned error message? */
612 lua_pop(L, 1); /* remove extra return */
613 luaL_addvalue(&msg); /* concatenate error message */
614 }
615 else
616 lua_pop(L, 2); /* remove both returns */
617 }
618#endif
619}
620
621
622static int ll_require (lua_State *L) {

Callers 1

ll_requireFunction · 0.85

Calls 9

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

Tested by

no test coverage detected