[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5.0 and 5.1 together
- From: John Belmonte <john@...>
- Date: Sun, 09 Apr 2006 16:57:33 -0400
I wrote:
> Diego Nehab wrote:
>
>>Cool. I totally agree with your suggestion. I guess back then I was in
>>Brazil and too busy with the beach. :)
>>
>>As for not needing the support of the authors, this would force us to
>>patch the lua.c and/or loadlib.c. Since the 5.1.1 has not yet been
>>released...
>>
>>So, what is it going to be, people?
>
>
> Patching Lua to take care of distribution details is not a big deal, we
> already do it for other things (e.g. patching luaconf.h to add /usr/...
> variants to search paths). Only one person need do the work and we can
> then share the patch. I'll take a stab at it this weekend.
Attached is a backwards-compatible patch to check e.g. LUA_5_1_PATH
before LUA_PATH when looking up Lua environment variables (LUA_PATH,
LUA_CPATH, and LUA_INIT). If the versioned variable exists then the
non-versioned one is not used at all.
--John
diff -urN lua-5.1.orig/src/loadlib.c lua-5.1/src/loadlib.c
--- lua-5.1.orig/src/loadlib.c 2005-12-29 10:32:11.000000000 -0500
+++ lua-5.1/src/loadlib.c 2006-04-09 16:24:16.000000000 -0400
@@ -586,13 +586,23 @@
/* }====================================================== */
+static const char * getlenv(lua_State *L, const char* envname) {
+ /* try version-specific name first (e.g. LUA_5_1_PATH for LUA_PATH) */
+ const char *envname2 = luaL_gsub(L, envname, "LUA", "LUA_5_1");
+ const char *val = getenv(envname2);
+ if (val == NULL)
+ val = getenv(envname);
+ lua_remove(L, -1);
+ return val;
+}
+
/* auxiliary mark (for internal use) */
#define AUXMARK "\1"
static void setpath (lua_State *L, const char *fieldname, const char *envname,
const char *def) {
- const char *path = getenv(envname);
+ const char *path = getlenv(L, envname);
if (path == NULL) /* no environment variable? */
lua_pushstring(L, def); /* use default */
else {
diff -urN lua-5.1.orig/src/lua.c lua-5.1/src/lua.c
--- lua-5.1.orig/src/lua.c 2005-12-29 11:23:32.000000000 -0500
+++ lua-5.1/src/lua.c 2006-04-09 16:24:22.000000000 -0400
@@ -305,8 +305,19 @@
}
+static const char * getlenv(lua_State *L, const char* envname) {
+ /* try version-specific name first (e.g. LUA_5_1_PATH for LUA_PATH) */
+ const char *envname2 = luaL_gsub(L, envname, "LUA", "LUA_5_1");
+ const char *val = getenv(envname2);
+ if (val == NULL)
+ val = getenv(envname);
+ lua_remove(L, -1);
+ return val;
+}
+
+
static int handle_luainit (lua_State *L) {
- const char *init = getenv("LUA_INIT");
+ const char *init = getlenv(L, "LUA_INIT");
if (init == NULL) return 0; /* status OK */
else if (init[0] == '@')
return dofile(L, init+1);