summaryrefslogtreecommitdiff
path: root/lua.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-03-13 00:57:46 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-03-13 00:57:46 -0300
commit489253d7530e372da8807f1ad083928c3545f772 (patch)
tree27af73f0d2809bef0b2366fee6e26cbbbe748887 /lua.h
parent25c557ec6367870c127e879cce8ed8fa21f34398 (diff)
downloadlua-github-489253d7530e372da8807f1ad083928c3545f772.tar.gz
better definitions for lua_[gs]etglobal + less uses of ENVIRONINDEX
Diffstat (limited to 'lua.h')
-rw-r--r--lua.h10
1 files changed, 7 insertions, 3 deletions
diff --git a/lua.h b/lua.h
index 055a8687..43bb8aec 100644
--- a/lua.h
+++ b/lua.h
@@ -1,5 +1,5 @@
/*
-** $Id: lua.h,v 1.260 2010/01/06 15:08:00 roberto Exp roberto $
+** $Id: lua.h,v 1.261 2010/01/11 17:15:11 roberto Exp roberto $
** Lua - A Scripting Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
@@ -297,8 +297,12 @@ LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
#define lua_newtable(L) lua_createtable(L, 0, 0)
-#define lua_setglobal(L,s) lua_setfield(L, LUA_ENVIRONINDEX, (s))
-#define lua_getglobal(L,s) lua_getfield(L, LUA_ENVIRONINDEX, (s))
+#define lua_setglobal(L,s) \
+ (lua_pushglobaltable(L), lua_pushvalue(L, -2), \
+ lua_setfield(L, -2, (s)), lua_pop(L, 2))
+
+#define lua_getglobal(L,s) \
+ (lua_pushglobaltable(L), lua_getfield(L, -1, (s)), lua_remove(L, -2))
#define lua_register(L,n,f) \
(lua_pushcfunction(L, (f)), lua_setfield(L, LUA_ENVIRONINDEX, (n)))