summaryrefslogtreecommitdiff
path: root/lua.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-07-25 12:03:37 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-07-25 12:03:37 -0300
commit73b0a3451d0bd59f1540271aa3b8d8de36b36580 (patch)
tree606dd5dc2208d97560b8cdea4a6f0e68070d62ad /lua.c
parent85c1461422a8a97a25ee385793def9c89e70739c (diff)
downloadlua-github-73b0a3451d0bd59f1540271aa3b8d8de36b36580.tar.gz
environment variables consulted by Lua may be version-specific
Diffstat (limited to 'lua.c')
-rw-r--r--lua.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/lua.c b/lua.c
index 6f80550b..5f68dd55 100644
--- a/lua.c
+++ b/lua.c
@@ -1,5 +1,5 @@
/*
-** $Id: lua.c,v 1.190 2010/04/14 15:14:21 roberto Exp roberto $
+** $Id: lua.c,v 1.191 2010/07/02 17:36:32 roberto Exp roberto $
** Lua stand-alone interpreter
** See Copyright Notice in lua.h
*/
@@ -31,10 +31,13 @@
#define LUA_MAXINPUT 512
#endif
-#if !defined(LUA_INIT_VAR)
-#define LUA_INIT_VAR "LUA_INIT"
+#if !defined(LUA_INIT)
+#define LUA_INIT "LUA_INIT"
#endif
+#define LUA_INITVERSION \
+ LUA_INIT "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR
+
/*
** 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) {
static int handle_luainit (lua_State *L) {
- const char *init = getenv(LUA_INIT_VAR);
+ const char *name = "=" LUA_INITVERSION;
+ const char *init = getenv(name + 1);
+ if (init == NULL) {
+ name = "=" LUA_INIT;
+ init = getenv(name + 1); /* try alternative name */
+ }
if (init == NULL) return LUA_OK;
else if (init[0] == '@')
return dofile(L, init+1);
else
- return dostring(L, init, "=" LUA_INIT_VAR);
+ return dostring(L, init, name);
}