MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / searchpath

Function searchpath

third-party/lua-5.5.0/src/loadlib.c:475–499  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

473
474
475static const char *searchpath (lua_State *L, const char *name,
476 const char *path,
477 const char *sep,
478 const char *dirsep) {
479 luaL_Buffer buff;
480 char *pathname; /* path with name inserted */
481 char *endpathname; /* its end */
482 const char *filename;
483 /* separator is non-empty and appears in 'name'? */
484 if (*sep != '\0' && strchr(name, *sep) != NULL)
485 name = luaL_gsub(L, name, sep, dirsep); /* replace it by 'dirsep' */
486 luaL_buffinit(L, &buff);
487 /* add path to the buffer, replacing marks ('?') with the file name */
488 luaL_addgsub(&buff, path, LUA_PATH_MARK, name);
489 luaL_addchar(&buff, '\0');
490 pathname = luaL_buffaddr(&buff); /* writable list of file names */
491 endpathname = pathname + luaL_bufflen(&buff) - 1;
492 while ((filename = getnextfilename(&pathname, endpathname)) != NULL) {
493 if (readable(filename)) /* does file exist and is readable? */
494 return lua_pushstring(L, filename); /* save and return name */
495 }
496 luaL_pushresult(&buff); /* push path to create error message */
497 pusherrornotfound(L, lua_tostring(L, -1)); /* create error message */
498 return NULL; /* not found */
499}
500
501
502static int ll_searchpath (lua_State *L) {

Callers 2

ll_searchpathFunction · 0.70
findfileFunction · 0.70

Calls 8

luaL_gsubFunction · 0.70
luaL_buffinitFunction · 0.70
luaL_addgsubFunction · 0.70
getnextfilenameFunction · 0.70
readableFunction · 0.70
lua_pushstringFunction · 0.70
luaL_pushresultFunction · 0.70
pusherrornotfoundFunction · 0.70

Tested by

no test coverage detected