MCPcopy Create free account
hub / github.com/DFHack/dfhack / searchpath

Function searchpath

depends/lua/src/loadlib.c:435–455  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

433
434
435static const char *searchpath (lua_State *L, const char *name,
436 const char *path,
437 const char *sep,
438 const char *dirsep) {
439 luaL_Buffer msg; /* to build error message */
440 luaL_buffinit(L, &msg);
441 if (*sep != '\0') /* non-empty separator? */
442 name = luaL_gsub(L, name, sep, dirsep); /* replace it by 'dirsep' */
443 while ((path = pushnexttemplate(L, path)) != NULL) {
444 const char *filename = luaL_gsub(L, lua_tostring(L, -1),
445 LUA_PATH_MARK, name);
446 lua_remove(L, -2); /* remove path template */
447 if (readable(filename)) /* does file exist and is readable? */
448 return filename; /* return that file name */
449 lua_pushfstring(L, "\n\tno file '%s'", filename);
450 lua_remove(L, -2); /* remove file name */
451 luaL_addvalue(&msg); /* concatenate error msg. entry */
452 }
453 luaL_pushresult(&msg); /* create error message */
454 return NULL; /* not found */
455}
456
457
458static int ll_searchpath (lua_State *L) {

Callers 2

ll_searchpathFunction · 0.85
findfileFunction · 0.85

Calls 7

luaL_buffinitFunction · 0.85
luaL_gsubFunction · 0.85
pushnexttemplateFunction · 0.85
readableFunction · 0.85
lua_pushfstringFunction · 0.85
luaL_addvalueFunction · 0.85
luaL_pushresultFunction · 0.85

Tested by

no test coverage detected