diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-08-30 15:35:14 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-08-30 15:35:14 -0300 |
commit | 7d309480dd783112aad8c4761921c4d45ec70327 (patch) | |
tree | b2fa8a177839f675e35a8ef626ac76c9dba6270b /lauxlib.c | |
parent | bcb2cb59ac235297e6ef8153ffd414836ae38efd (diff) | |
download | lua-7d309480dd783112aad8c4761921c4d45ec70327.tar.gz lua-7d309480dd783112aad8c4761921c4d45ec70327.tar.bz2 lua-7d309480dd783112aad8c4761921c4d45ec70327.zip |
new way to handle _PATH (old LUA_PATH)
Diffstat (limited to 'lauxlib.c')
-rw-r--r-- | lauxlib.c | 19 |
1 files changed, 2 insertions, 17 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.121 2004/07/13 20:11:32 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.122 2004/08/13 19:52:53 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -341,17 +341,6 @@ LUALIB_API int luaL_getn (lua_State *L, int t) { | |||
341 | /* }====================================================== */ | 341 | /* }====================================================== */ |
342 | 342 | ||
343 | 343 | ||
344 | static const char *getpath (lua_State *L) { | ||
345 | const char *path; | ||
346 | lua_getglobal(L, LUA_PATH); /* try global variable */ | ||
347 | path = lua_tostring(L, -1); | ||
348 | if (path) return path; | ||
349 | path = getenv(LUA_PATH); /* else try environment variable */ | ||
350 | if (path) return path; | ||
351 | return LUA_PATH_DEFAULT; /* else use default */ | ||
352 | } | ||
353 | |||
354 | |||
355 | static const char *pushnexttemplate (lua_State *L, const char *path) { | 344 | static const char *pushnexttemplate (lua_State *L, const char *path) { |
356 | const char *l; | 345 | const char *l; |
357 | if (*path == '\0') return NULL; /* no more templates */ | 346 | if (*path == '\0') return NULL; /* no more templates */ |
@@ -383,10 +372,7 @@ static const char *luaL_gsub (lua_State *L, const char *s, | |||
383 | LUALIB_API const char *luaL_searchpath (lua_State *L, const char *name, | 372 | LUALIB_API const char *luaL_searchpath (lua_State *L, const char *name, |
384 | const char *path) { | 373 | const char *path) { |
385 | FILE *f; | 374 | FILE *f; |
386 | const char *p; | 375 | const char *p = path; |
387 | if (path == NULL) path = getpath(L); | ||
388 | else lua_pushnil(L); /* to balance item pushed by `getpath' */ | ||
389 | p = path; | ||
390 | for (;;) { | 376 | for (;;) { |
391 | const char *fname; | 377 | const char *fname; |
392 | if ((p = pushnexttemplate(L, p)) == NULL) { | 378 | if ((p = pushnexttemplate(L, p)) == NULL) { |
@@ -398,7 +384,6 @@ LUALIB_API const char *luaL_searchpath (lua_State *L, const char *name, | |||
398 | f = fopen(fname, "r"); /* try to read it */ | 384 | f = fopen(fname, "r"); /* try to read it */ |
399 | if (f) { | 385 | if (f) { |
400 | fclose(f); | 386 | fclose(f); |
401 | lua_remove(L, -2); /* remove path */ | ||
402 | return fname; | 387 | return fname; |
403 | } | 388 | } |
404 | lua_pop(L, 1); /* remove file name */ | 389 | lua_pop(L, 1); /* remove file name */ |