diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-03-13 00:57:46 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-03-13 00:57:46 -0300 |
| commit | 489253d7530e372da8807f1ad083928c3545f772 (patch) | |
| tree | 27af73f0d2809bef0b2366fee6e26cbbbe748887 /lbaselib.c | |
| parent | 25c557ec6367870c127e879cce8ed8fa21f34398 (diff) | |
| download | lua-489253d7530e372da8807f1ad083928c3545f772.tar.gz lua-489253d7530e372da8807f1ad083928c3545f772.tar.bz2 lua-489253d7530e372da8807f1ad083928c3545f772.zip | |
better definitions for lua_[gs]etglobal + less uses of ENVIRONINDEX
Diffstat (limited to 'lbaselib.c')
| -rw-r--r-- | lbaselib.c | 11 |
1 files changed, 6 insertions, 5 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.235 2009/12/28 16:30:31 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.236 2010/03/12 19:14:06 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_ENVIRONINDEX, "tostring"); | 26 | lua_getglobal(L, "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; |
| @@ -679,11 +679,12 @@ static void auxopen (lua_State *L, const char *name, | |||
| 679 | static void base_open (lua_State *L) { | 679 | static void base_open (lua_State *L) { |
| 680 | /* set global _G */ | 680 | /* set global _G */ |
| 681 | lua_pushglobaltable(L); | 681 | lua_pushglobaltable(L); |
| 682 | lua_setfield(L, LUA_ENVIRONINDEX, "_G"); | 682 | lua_pushglobaltable(L); |
| 683 | lua_setfield(L, -2, "_G"); | ||
| 683 | /* open lib into global table */ | 684 | /* open lib into global table */ |
| 684 | luaL_register(L, "_G", base_funcs); | 685 | luaL_register(L, "_G", base_funcs); |
| 685 | lua_pushliteral(L, LUA_VERSION); | 686 | lua_pushliteral(L, LUA_VERSION); |
| 686 | lua_setfield(L, LUA_ENVIRONINDEX, "_VERSION"); /* set global _VERSION */ | 687 | lua_setfield(L, -2, "_VERSION"); /* set global _VERSION */ |
| 687 | /* `ipairs' and `pairs' need auxiliary functions as upvalues */ | 688 | /* `ipairs' and `pairs' need auxiliary functions as upvalues */ |
| 688 | auxopen(L, "ipairs", luaB_ipairs, ipairsaux); | 689 | auxopen(L, "ipairs", luaB_ipairs, ipairsaux); |
| 689 | auxopen(L, "pairs", luaB_pairs, luaB_next); | 690 | auxopen(L, "pairs", luaB_pairs, luaB_next); |
| @@ -694,7 +695,7 @@ static void base_open (lua_State *L) { | |||
| 694 | lua_pushliteral(L, "kv"); | 695 | lua_pushliteral(L, "kv"); |
| 695 | lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */ | 696 | lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */ |
| 696 | lua_pushcclosure(L, luaB_newproxy, 1); | 697 | lua_pushcclosure(L, luaB_newproxy, 1); |
| 697 | lua_setfield(L, LUA_ENVIRONINDEX, "newproxy"); /* set global `newproxy' */ | 698 | lua_setfield(L, -2, "newproxy"); /* set global `newproxy' */ |
| 698 | } | 699 | } |
| 699 | 700 | ||
| 700 | 701 | ||
