diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-09-30 17:49:47 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-09-30 17:49:47 -0300 |
| commit | ba21aa8b2b29f516f1f488f996fc899c62f7105b (patch) | |
| tree | 73ca0f540f0188e4f32acb5657c3c8c6e3d4cfc1 | |
| parent | d119cf30350593caa4bebdc5c4e3123f3cd269e0 (diff) | |
| download | lua-ba21aa8b2b29f516f1f488f996fc899c62f7105b.tar.gz lua-ba21aa8b2b29f516f1f488f996fc899c62f7105b.tar.bz2 lua-ba21aa8b2b29f516f1f488f996fc899c62f7105b.zip | |
'cpcall' must ensure correct environment for called function
| -rw-r--r-- | lstate.c | 7 |
1 files changed, 5 insertions, 2 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.c,v 2.59 2009/09/21 12:09:52 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 2.60 2009/09/28 13:50:19 roberto Exp roberto $ |
| 3 | ** Global State | 3 | ** Global State |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -98,7 +98,10 @@ static void freestack (lua_State *L) { | |||
| 98 | */ | 98 | */ |
| 99 | static int cpcall (lua_State *L) { | 99 | static int cpcall (lua_State *L) { |
| 100 | lua_CFunction f = *(lua_CFunction *)lua_touserdata(L, 1); | 100 | lua_CFunction f = *(lua_CFunction *)lua_touserdata(L, 1); |
| 101 | lua_remove(L, 1); | 101 | lua_remove(L, 1); /* remove f from stack */ |
| 102 | /* restore original environment for 'cpcall' */ | ||
| 103 | lua_pushvalue(L, LUA_GLOBALSINDEX); | ||
| 104 | lua_replace(L, LUA_ENVIRONINDEX); | ||
| 102 | return f(L); | 105 | return f(L); |
| 103 | } | 106 | } |
| 104 | 107 | ||
