| 364 | |
| 365 | |
| 366 | static 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 | |
| 389 | static void loaderror (lua_State *L, const char *filename) { |
no test coverage detected