diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-12-22 13:32:50 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-12-22 13:32:50 -0200 |
| commit | f84b575cfa52dc832751846aa0b4c8ff437d3ca3 (patch) | |
| tree | 246ef484b08d132d006c16a6c8cbe55e61c3bfce /lbaselib.c | |
| parent | 3cb343efd644fb771b6d8193406afd49527dc1ec (diff) | |
| download | lua-f84b575cfa52dc832751846aa0b4c8ff437d3ca3.tar.gz lua-f84b575cfa52dc832751846aa0b4c8ff437d3ca3.tar.bz2 lua-f84b575cfa52dc832751846aa0b4c8ff437d3ca3.zip | |
no more pseudoindex LUA_GLOBALSINDEX; global table now accessible
through registry
Diffstat (limited to 'lbaselib.c')
| -rw-r--r-- | lbaselib.c | 14 |
1 files changed, 7 insertions, 7 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.232 2009/12/15 11:25:16 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.233 2009/12/17 16:20:01 roberto Exp roberto $ |
| 3 | ** Basic library | 3 | ** Basic library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -23,7 +23,7 @@ | |||
| 23 | static int luaB_print (lua_State *L) { | 23 | static int luaB_print (lua_State *L) { |
| 24 | int n = lua_gettop(L); /* number of arguments */ | 24 | int n = lua_gettop(L); /* number of arguments */ |
| 25 | int i; | 25 | int i; |
| 26 | lua_getfield(L, LUA_GLOBALSINDEX, "tostring"); | 26 | lua_getfield(L, LUA_ENVIRONINDEX, "tostring"); |
| 27 | for (i=1; i<=n; i++) { | 27 | for (i=1; i<=n; i++) { |
| 28 | const char *s; | 28 | const char *s; |
| 29 | size_t l; | 29 | size_t l; |
| @@ -125,7 +125,7 @@ static void getfunc (lua_State *L, int opt) { | |||
| 125 | static int luaB_getfenv (lua_State *L) { | 125 | static int luaB_getfenv (lua_State *L) { |
| 126 | getfunc(L, 1); | 126 | getfunc(L, 1); |
| 127 | if (lua_iscfunction(L, -1)) /* is a C function? */ | 127 | if (lua_iscfunction(L, -1)) /* is a C function? */ |
| 128 | lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the global env. */ | 128 | lua_pushglobaltable(L); /* return the global env. */ |
| 129 | else | 129 | else |
| 130 | lua_getfenv(L, -1); | 130 | lua_getfenv(L, -1); |
| 131 | return 1; | 131 | return 1; |
| @@ -695,12 +695,12 @@ static void auxopen (lua_State *L, const char *name, | |||
| 695 | 695 | ||
| 696 | static void base_open (lua_State *L) { | 696 | static void base_open (lua_State *L) { |
| 697 | /* set global _G */ | 697 | /* set global _G */ |
| 698 | lua_pushvalue(L, LUA_GLOBALSINDEX); | 698 | lua_pushglobaltable(L); |
| 699 | lua_setfield(L, LUA_GLOBALSINDEX, "_G"); | 699 | lua_setfield(L, LUA_ENVIRONINDEX, "_G"); |
| 700 | /* open lib into global table */ | 700 | /* open lib into global table */ |
| 701 | luaL_register(L, "_G", base_funcs); | 701 | luaL_register(L, "_G", base_funcs); |
| 702 | lua_pushliteral(L, LUA_VERSION); | 702 | lua_pushliteral(L, LUA_VERSION); |
| 703 | lua_setfield(L, LUA_GLOBALSINDEX, "_VERSION"); /* set global _VERSION */ | 703 | lua_setfield(L, LUA_ENVIRONINDEX, "_VERSION"); /* set global _VERSION */ |
| 704 | /* `ipairs' and `pairs' need auxiliary functions as upvalues */ | 704 | /* `ipairs' and `pairs' need auxiliary functions as upvalues */ |
| 705 | auxopen(L, "ipairs", luaB_ipairs, ipairsaux); | 705 | auxopen(L, "ipairs", luaB_ipairs, ipairsaux); |
| 706 | auxopen(L, "pairs", luaB_pairs, luaB_next); | 706 | auxopen(L, "pairs", luaB_pairs, luaB_next); |
| @@ -711,7 +711,7 @@ static void base_open (lua_State *L) { | |||
| 711 | lua_pushliteral(L, "kv"); | 711 | lua_pushliteral(L, "kv"); |
| 712 | lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */ | 712 | lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */ |
| 713 | lua_pushcclosure(L, luaB_newproxy, 1); | 713 | lua_pushcclosure(L, luaB_newproxy, 1); |
| 714 | lua_setfield(L, LUA_GLOBALSINDEX, "newproxy"); /* set global `newproxy' */ | 714 | lua_setfield(L, LUA_ENVIRONINDEX, "newproxy"); /* set global `newproxy' */ |
| 715 | } | 715 | } |
| 716 | 716 | ||
| 717 | 717 | ||
