MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / searchpath

Function searchpath

3rd/lua-5.4.3/src/loadlib.c:481–505  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

ll_searchpathFunction · 0.85
findfileFunction · 0.85

Calls 8

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

Tested by

no test coverage detected