| 433 | |
| 434 | |
| 435 | static 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 | |
| 458 | static int ll_searchpath (lua_State *L) { |
no test coverage detected