diff options
| -rw-r--r-- | loadlib.c | 14 |
1 files changed, 9 insertions, 5 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: loadlib.c,v 1.93 2010/11/10 18:05:36 roberto Exp roberto $ | 2 | ** $Id: loadlib.c,v 1.94 2010/11/10 20:00:04 roberto Exp roberto $ |
| 3 | ** Dynamic library loader for Lua | 3 | ** Dynamic library loader for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | ** | 5 | ** |
| @@ -321,8 +321,10 @@ static const char *pushnexttemplate (lua_State *L, const char *path) { | |||
| 321 | 321 | ||
| 322 | 322 | ||
| 323 | static const char *searchpath (lua_State *L, const char *name, | 323 | static const char *searchpath (lua_State *L, const char *name, |
| 324 | const char *path) { | 324 | const char *path, |
| 325 | name = luaL_gsub(L, name, ".", LUA_DIRSEP); | 325 | const char *sep) { |
| 326 | if (*sep != '\0') /* non-empty separator? */ | ||
| 327 | name = luaL_gsub(L, name, sep, LUA_DIRSEP); /* replace it by proper one */ | ||
| 326 | lua_pushliteral(L, ""); /* error accumulator */ | 328 | lua_pushliteral(L, ""); /* error accumulator */ |
| 327 | while ((path = pushnexttemplate(L, path)) != NULL) { | 329 | while ((path = pushnexttemplate(L, path)) != NULL) { |
| 328 | const char *filename = luaL_gsub(L, lua_tostring(L, -1), | 330 | const char *filename = luaL_gsub(L, lua_tostring(L, -1), |
| @@ -339,7 +341,9 @@ static const char *searchpath (lua_State *L, const char *name, | |||
| 339 | 341 | ||
| 340 | 342 | ||
| 341 | static int ll_searchpath (lua_State *L) { | 343 | static int ll_searchpath (lua_State *L) { |
| 342 | const char *f = searchpath(L, luaL_checkstring(L, 1), luaL_checkstring(L, 2)); | 344 | const char *f = searchpath(L, luaL_checkstring(L, 1), |
| 345 | luaL_checkstring(L, 2), | ||
| 346 | luaL_optstring(L, 3, ".")); | ||
| 343 | if (f != NULL) return 1; | 347 | if (f != NULL) return 1; |
| 344 | else { /* error message is on top of the stack */ | 348 | else { /* error message is on top of the stack */ |
| 345 | lua_pushnil(L); | 349 | lua_pushnil(L); |
| @@ -356,7 +360,7 @@ static const char *findfile (lua_State *L, const char *name, | |||
| 356 | path = lua_tostring(L, -1); | 360 | path = lua_tostring(L, -1); |
| 357 | if (path == NULL) | 361 | if (path == NULL) |
| 358 | luaL_error(L, LUA_QL("package.%s") " must be a string", pname); | 362 | luaL_error(L, LUA_QL("package.%s") " must be a string", pname); |
| 359 | return searchpath(L, name, path); | 363 | return searchpath(L, name, path, "."); |
| 360 | } | 364 | } |
| 361 | 365 | ||
| 362 | 366 | ||
