MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / findfile

Function findfile

other_src/lua/src/loadlib.cpp:366–386  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

364
365
366static const char *findfile (lua_State *L, const char *name,
367 const char *pname) {
368 const char *path;
369 name = luaL_gsub(L, name, ".", LUA_DIRSEP);
370 lua_getfield(L, LUA_ENVIRONINDEX, pname);
371 path = lua_tostring(L, -1);
372 if (path == NULL)
373 luaL_error(L, LUA_QL("package.%s") " must be a string", pname);
374 lua_pushliteral(L, ""); /* error accumulator */
375 while ((path = pushnexttemplate(L, path)) != NULL) {
376 const char *filename;
377 filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name);
378 lua_remove(L, -2); /* remove path template */
379 if (readable(filename)) /* does file exist and is readable? */
380 return filename; /* return that file name */
381 lua_pushfstring(L, "\n\tno file " LUA_QS, filename);
382 lua_remove(L, -2); /* remove file name */
383 lua_concat(L, 2); /* add entry to possible error message */
384 }
385 return NULL; /* not found */
386}
387
388
389static void loaderror (lua_State *L, const char *filename) {

Callers 3

loader_LuaFunction · 0.70
loader_CFunction · 0.70
loader_CrootFunction · 0.70

Calls 8

luaL_gsubFunction · 0.70
lua_getfieldFunction · 0.70
luaL_errorFunction · 0.70
pushnexttemplateFunction · 0.70
lua_removeFunction · 0.70
readableFunction · 0.70
lua_pushfstringFunction · 0.70
lua_concatFunction · 0.70

Tested by

no test coverage detected