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 /loadlib.c | |
parent | 85c1461422a8a97a25ee385793def9c89e70739c (diff) | |
download | lua-73b0a3451d0bd59f1540271aa3b8d8de36b36580.tar.gz lua-73b0a3451d0bd59f1540271aa3b8d8de36b36580.tar.bz2 lua-73b0a3451d0bd59f1540271aa3b8d8de36b36580.zip |
environment variables consulted by Lua may be version-specific
Diffstat (limited to 'loadlib.c')
-rw-r--r-- | loadlib.c | 30 |
1 files changed, 19 insertions, 11 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"); |