From e2fc2ce8dfe107d1e2742b459c2aaf137227bbc1 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 12 Dec 2011 14:34:03 -0200 Subject: new way to handle -E option (write a mark in the registry to avoid reading environment variables) --- loadlib.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'loadlib.c') diff --git a/loadlib.c b/loadlib.c index 02787ef7..f2d7fe3c 100644 --- a/loadlib.c +++ b/loadlib.c @@ -1,5 +1,5 @@ /* -** $Id: loadlib.c,v 1.106 2011/11/28 17:27:51 roberto Exp roberto $ +** $Id: loadlib.c,v 1.107 2011/11/30 12:58:57 roberto Exp roberto $ ** Dynamic library loader for Lua ** See Copyright Notice in lua.h ** @@ -615,12 +615,25 @@ static int ll_seeall (lua_State *L) { /* auxiliary mark (for internal use) */ #define AUXMARK "\1" + +/* +** return registry.LUA_NOENV as a boolean +*/ +static int noenv (lua_State *L) { + int b; + lua_getfield(L, LUA_REGISTRYINDEX, "LUA_NOENV"); + b = lua_toboolean(L, -1); + lua_pop(L, 1); /* remove value */ + return b; +} + + static void setpath (lua_State *L, const char *fieldname, const char *envname1, const char *envname2, const char *def) { const char *path = getenv(envname1); if (path == NULL) /* no environment variable? */ path = getenv(envname2); /* try alternative name */ - if (path == NULL) /* no environment variable? */ + if (path == NULL || noenv(L)) /* no environment variable? */ lua_pushstring(L, def); /* use default */ else { /* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */ -- cgit v1.2.3-55-g6feb