MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / searchpath

Function searchpath

extlibs/lua/src/loadlib.c:474–498  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

ll_searchpathFunction · 0.85
findfileFunction · 0.85

Calls 8

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

Tested by

no test coverage detected