no more pseudoindex LUA_GLOBALSINDEX; global table now accessible

through registry
This commit is contained in:
Roberto Ierusalimschy
2009-12-22 13:32:50 -02:00
parent 3cb343efd6
commit f84b575cfa
12 changed files with 63 additions and 53 deletions

View File

@@ -1,5 +1,5 @@
/*
** $Id: lbaselib.c,v 1.232 2009/12/15 11:25:16 roberto Exp roberto $
** $Id: lbaselib.c,v 1.233 2009/12/17 16:20:01 roberto Exp roberto $
** Basic library
** See Copyright Notice in lua.h
*/
@@ -23,7 +23,7 @@
static int luaB_print (lua_State *L) {
int n = lua_gettop(L); /* number of arguments */
int i;
lua_getfield(L, LUA_GLOBALSINDEX, "tostring");
lua_getfield(L, LUA_ENVIRONINDEX, "tostring");
for (i=1; i<=n; i++) {
const char *s;
size_t l;
@@ -125,7 +125,7 @@ static void getfunc (lua_State *L, int opt) {
static int luaB_getfenv (lua_State *L) {
getfunc(L, 1);
if (lua_iscfunction(L, -1)) /* is a C function? */
lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the global env. */
lua_pushglobaltable(L); /* return the global env. */
else
lua_getfenv(L, -1);
return 1;
@@ -695,12 +695,12 @@ static void auxopen (lua_State *L, const char *name,
static void base_open (lua_State *L) {
/* set global _G */
lua_pushvalue(L, LUA_GLOBALSINDEX);
lua_setfield(L, LUA_GLOBALSINDEX, "_G");
lua_pushglobaltable(L);
lua_setfield(L, LUA_ENVIRONINDEX, "_G");
/* open lib into global table */
luaL_register(L, "_G", base_funcs);
lua_pushliteral(L, LUA_VERSION);
lua_setfield(L, LUA_GLOBALSINDEX, "_VERSION"); /* set global _VERSION */
lua_setfield(L, LUA_ENVIRONINDEX, "_VERSION"); /* set global _VERSION */
/* `ipairs' and `pairs' need auxiliary functions as upvalues */
auxopen(L, "ipairs", luaB_ipairs, ipairsaux);
auxopen(L, "pairs", luaB_pairs, luaB_next);
@@ -711,7 +711,7 @@ static void base_open (lua_State *L) {
lua_pushliteral(L, "kv");
lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */
lua_pushcclosure(L, luaB_newproxy, 1);
lua_setfield(L, LUA_GLOBALSINDEX, "newproxy"); /* set global `newproxy' */
lua_setfield(L, LUA_ENVIRONINDEX, "newproxy"); /* set global `newproxy' */
}