aboutsummaryrefslogtreecommitdiff
path: root/lbaselib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-02-18 10:40:02 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-02-18 10:40:02 -0200
commit7d45a5f48ff32a4e09a1734de23823943d6a6b28 (patch)
treede7bef1faf37d9b639928e5269e89d7112b5b6fa /lbaselib.c
parent73d764024451c24bc43b8e5102fe90974a86b7f4 (diff)
downloadlua-7d45a5f48ff32a4e09a1734de23823943d6a6b28.tar.gz
lua-7d45a5f48ff32a4e09a1734de23823943d6a6b28.tar.bz2
lua-7d45a5f48ff32a4e09a1734de23823943d6a6b28.zip
C functions and userdata also have environments
Diffstat (limited to 'lbaselib.c')
-rw-r--r--lbaselib.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/lbaselib.c b/lbaselib.c
index ae3ad956..7acbba4b 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.165 2005/01/14 14:19:42 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.166 2005/02/14 13:19:44 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*/
@@ -131,7 +131,10 @@ static void getfunc (lua_State *L) {
131 131
132static int luaB_getfenv (lua_State *L) { 132static int luaB_getfenv (lua_State *L) {
133 getfunc(L); 133 getfunc(L);
134 lua_getfenv(L, -1); 134 if (lua_iscfunction(L, -1)) /* is a C function? */
135 lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the global env. */
136 else
137 lua_getfenv(L, -1);
135 return 1; 138 return 1;
136} 139}
137 140
@@ -144,8 +147,8 @@ static int luaB_setfenv (lua_State *L) {
144 lua_replace(L, LUA_GLOBALSINDEX); 147 lua_replace(L, LUA_GLOBALSINDEX);
145 return 0; 148 return 0;
146 } 149 }
147 else if (lua_setfenv(L, -2) == 0) 150 else if (lua_iscfunction(L, -2) || lua_setfenv(L, -2) == 0)
148 luaL_error(L, "`setfenv' cannot change environment of given function"); 151 luaL_error(L, "`setfenv' cannot change environment of given object");
149 return 1; 152 return 1;
150} 153}
151 154