diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-07-25 12:03:37 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-07-25 12:03:37 -0300 |
| commit | 73b0a3451d0bd59f1540271aa3b8d8de36b36580 (patch) | |
| tree | 606dd5dc2208d97560b8cdea4a6f0e68070d62ad | |
| parent | 85c1461422a8a97a25ee385793def9c89e70739c (diff) | |
| download | lua-73b0a3451d0bd59f1540271aa3b8d8de36b36580.tar.gz lua-73b0a3451d0bd59f1540271aa3b8d8de36b36580.tar.bz2 lua-73b0a3451d0bd59f1540271aa3b8d8de36b36580.zip | |
environment variables consulted by Lua may be version-specific
| -rw-r--r-- | loadlib.c | 30 | ||||
| -rw-r--r-- | lua.c | 18 |
2 files changed, 32 insertions, 16 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: loadlib.c,v 1.86 2010/06/30 17:40:27 roberto Exp roberto $ | 2 | ** $Id: loadlib.c,v 1.87 2010/07/02 11:38:13 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 | ** |
| @@ -23,17 +23,21 @@ | |||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | /* | 25 | /* |
| 26 | ** LUA_PATH_VAR and LUA_CPATH_VAR are the names of the environment | 26 | ** LUA_PATH and LUA_CPATH are the names of the environment |
| 27 | ** variables that Lua check to set its paths. | 27 | ** variables that Lua check to set its paths. |
| 28 | */ | 28 | */ |
| 29 | #if !defined(LUA_PATH_VAR) | 29 | #if !defined(LUA_PATH) |
| 30 | #define LUA_PATH_VAR "LUA_PATH" | 30 | #define LUA_PATH "LUA_PATH" |
| 31 | #endif | 31 | #endif |
| 32 | 32 | ||
| 33 | #if !defined(LUA_CPATH_VAR) | 33 | #if !defined(LUA_CPATH) |
| 34 | #define LUA_CPATH_VAR "LUA_CPATH" | 34 | #define LUA_CPATH "LUA_CPATH" |
| 35 | #endif | 35 | #endif |
| 36 | 36 | ||
| 37 | #define LUA_PATHSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR | ||
| 38 | |||
| 39 | #define LUA_PATHVERSION LUA_PATH LUA_PATHSUFFIX | ||
| 40 | #define LUA_CPATHVERSION LUA_CPATH LUA_PATHSUFFIX | ||
| 37 | 41 | ||
| 38 | /* | 42 | /* |
| 39 | ** LUA_PATH_SEP is the character that separates templates in a path. | 43 | ** LUA_PATH_SEP is the character that separates templates in a path. |
| @@ -573,9 +577,11 @@ static int ll_seeall (lua_State *L) { | |||
| 573 | /* auxiliary mark (for internal use) */ | 577 | /* auxiliary mark (for internal use) */ |
| 574 | #define AUXMARK "\1" | 578 | #define AUXMARK "\1" |
| 575 | 579 | ||
| 576 | static void setpath (lua_State *L, const char *fieldname, const char *envname, | 580 | static void setpath (lua_State *L, const char *fieldname, const char *envname1, |
| 577 | const char *def) { | 581 | const char *envname2, const char *def) { |
| 578 | const char *path = getenv(envname); | 582 | const char *path = getenv(envname1); |
| 583 | if (path == NULL) /* no environment variable? */ | ||
| 584 | path = getenv(envname2); /* try alternative name */ | ||
| 579 | if (path == NULL) /* no environment variable? */ | 585 | if (path == NULL) /* no environment variable? */ |
| 580 | lua_pushstring(L, def); /* use default */ | 586 | lua_pushstring(L, def); /* use default */ |
| 581 | else { | 587 | else { |
| @@ -626,8 +632,10 @@ LUAMOD_API int luaopen_package (lua_State *L) { | |||
| 626 | lua_rawseti(L, -2, i+1); | 632 | lua_rawseti(L, -2, i+1); |
| 627 | } | 633 | } |
| 628 | lua_setfield(L, -2, "loaders"); /* put it in field `loaders' */ | 634 | lua_setfield(L, -2, "loaders"); /* put it in field `loaders' */ |
| 629 | setpath(L, "path", LUA_PATH_VAR, LUA_PATH_DEFAULT); /* set field `path' */ | 635 | /* set field 'path' */ |
| 630 | setpath(L, "cpath", LUA_CPATH_VAR, LUA_CPATH_DEFAULT); /* set field `cpath' */ | 636 | setpath(L, "path", LUA_PATHVERSION, LUA_PATH, LUA_PATH_DEFAULT); |
| 637 | /* set field 'cpath' */ | ||
| 638 | setpath(L, "cpath", LUA_CPATHVERSION, LUA_CPATH, LUA_CPATH_DEFAULT); | ||
| 631 | /* store config information */ | 639 | /* store config information */ |
| 632 | lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATH_SEP "\n" LUA_PATH_MARK "\n" | 640 | lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATH_SEP "\n" LUA_PATH_MARK "\n" |
| 633 | LUA_EXEC_DIR "\n" LUA_IGMARK "\n"); | 641 | LUA_EXEC_DIR "\n" LUA_IGMARK "\n"); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.c,v 1.190 2010/04/14 15:14:21 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.191 2010/07/02 17:36:32 roberto Exp roberto $ |
| 3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -31,10 +31,13 @@ | |||
| 31 | #define LUA_MAXINPUT 512 | 31 | #define LUA_MAXINPUT 512 |
| 32 | #endif | 32 | #endif |
| 33 | 33 | ||
| 34 | #if !defined(LUA_INIT_VAR) | 34 | #if !defined(LUA_INIT) |
| 35 | #define LUA_INIT_VAR "LUA_INIT" | 35 | #define LUA_INIT "LUA_INIT" |
| 36 | #endif | 36 | #endif |
| 37 | 37 | ||
| 38 | #define LUA_INITVERSION \ | ||
| 39 | LUA_INIT "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR | ||
| 40 | |||
| 38 | 41 | ||
| 39 | /* | 42 | /* |
| 40 | ** lua_stdin_is_tty detects whether the standard input is a 'tty' (that | 43 | ** lua_stdin_is_tty detects whether the standard input is a 'tty' (that |
| @@ -409,12 +412,17 @@ static int runargs (lua_State *L, char **argv, int n) { | |||
| 409 | 412 | ||
| 410 | 413 | ||
| 411 | static int handle_luainit (lua_State *L) { | 414 | static int handle_luainit (lua_State *L) { |
| 412 | const char *init = getenv(LUA_INIT_VAR); | 415 | const char *name = "=" LUA_INITVERSION; |
| 416 | const char *init = getenv(name + 1); | ||
| 417 | if (init == NULL) { | ||
| 418 | name = "=" LUA_INIT; | ||
| 419 | init = getenv(name + 1); /* try alternative name */ | ||
| 420 | } | ||
| 413 | if (init == NULL) return LUA_OK; | 421 | if (init == NULL) return LUA_OK; |
| 414 | else if (init[0] == '@') | 422 | else if (init[0] == '@') |
| 415 | return dofile(L, init+1); | 423 | return dofile(L, init+1); |
| 416 | else | 424 | else |
| 417 | return dostring(L, init, "=" LUA_INIT_VAR); | 425 | return dostring(L, init, name); |
| 418 | } | 426 | } |
| 419 | 427 | ||
| 420 | 428 | ||
