| 13117 | |
| 13118 | |
| 13119 | static const char *findfile (lua_State *L, const char *name, |
| 13120 | const char *pname) { |
| 13121 | const char *path; |
| 13122 | name = luaL_gsub(L, name, ".", LUA_DIRSEP); |
| 13123 | lua_getfield(L, LUA_ENVIRONINDEX, pname); |
| 13124 | path = lua_tostring(L, -1); |
| 13125 | if (path == NULL) |
| 13126 | luaL_error(L, LUA_QL("package.%s") " must be a string", pname); |
| 13127 | lua_pushliteral(L, ""); /* error accumulator */ |
| 13128 | while ((path = pushnexttemplate(L, path)) != NULL) { |
| 13129 | const char *filename; |
| 13130 | filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name); |
| 13131 | lua_remove(L, -2); /* remove path template */ |
| 13132 | if (readable(filename)) /* does file exist and is readable? */ |
| 13133 | return filename; /* return that file name */ |
| 13134 | lua_pushfstring(L, "\n\tno file " LUA_QS, filename); |
| 13135 | lua_remove(L, -2); /* remove file name */ |
| 13136 | lua_concat(L, 2); /* add entry to possible error message */ |
| 13137 | } |
| 13138 | return NULL; /* not found */ |
| 13139 | } |
| 13140 | |
| 13141 | |
| 13142 | static void loaderror (lua_State *L, const char *filename) { |
no test coverage detected