diff options
| -rw-r--r-- | lapi.c | 44 | ||||
| -rw-r--r-- | lauxlib.c | 6 | ||||
| -rw-r--r-- | lbaselib.c | 5 | ||||
| -rw-r--r-- | loadlib.c | 5 | ||||
| -rw-r--r-- | lstate.c | 5 | ||||
| -rw-r--r-- | ltests.c | 6 | ||||
| -rw-r--r-- | lua.h | 3 |
7 files changed, 45 insertions, 29 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.91 2009/09/21 12:09:52 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.92 2009/09/28 16:32:50 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -185,32 +185,46 @@ LUA_API void lua_insert (lua_State *L, int idx) { | |||
| 185 | } | 185 | } |
| 186 | 186 | ||
| 187 | 187 | ||
| 188 | LUA_API void lua_replace (lua_State *L, int idx) { | 188 | static void moveto (lua_State *L, TValue *fr, int idx) { |
| 189 | StkId o; | 189 | TValue *to = index2addr(L, idx); |
| 190 | lua_lock(L); | 190 | api_checkvalidindex(L, to); |
| 191 | /* explicit test for incompatible code */ | ||
| 192 | if (idx == LUA_ENVIRONINDEX && L->ci->previous == NULL) | ||
| 193 | luaG_runerror(L, "no calling environment"); | ||
| 194 | api_checknelems(L, 1); | ||
| 195 | o = index2addr(L, idx); | ||
| 196 | api_checkvalidindex(L, o); | ||
| 197 | if (idx == LUA_ENVIRONINDEX) { | 191 | if (idx == LUA_ENVIRONINDEX) { |
| 198 | Closure *func = curr_func(L); | 192 | Closure *func = curr_func(L); |
| 199 | api_check(L, ttistable(L->top - 1), "table expected"); | 193 | api_check(L, ttistable(fr), "table expected"); |
| 200 | func->c.env = hvalue(L->top - 1); | 194 | func->c.env = hvalue(fr); |
| 201 | luaC_barrier(L, func, L->top - 1); | 195 | luaC_barrier(L, func, fr); |
| 202 | } | 196 | } |
| 203 | else { | 197 | else { |
| 204 | setobj(L, o, L->top - 1); | 198 | setobj(L, to, fr); |
| 205 | if (idx < LUA_GLOBALSINDEX) /* function upvalue? */ | 199 | if (idx < LUA_GLOBALSINDEX) /* function upvalue? */ |
| 206 | luaC_barrier(L, curr_func(L), L->top - 1); | 200 | luaC_barrier(L, curr_func(L), fr); |
| 207 | } | 201 | } |
| 208 | /* LUA_GLOBALSINDEX does not need gc barrier (threads are never black) */ | 202 | /* LUA_GLOBALSINDEX does not need gc barrier (threads are never black) */ |
| 203 | } | ||
| 204 | |||
| 205 | |||
| 206 | LUA_API void lua_replace (lua_State *L, int idx) { | ||
| 207 | lua_lock(L); | ||
| 208 | /* explicit test for incompatible code */ | ||
| 209 | if (idx == LUA_ENVIRONINDEX && L->ci->previous == NULL) | ||
| 210 | luaG_runerror(L, "no calling environment"); | ||
| 211 | api_checknelems(L, 1); | ||
| 212 | moveto(L, L->top - 1, idx); | ||
| 209 | L->top--; | 213 | L->top--; |
| 210 | lua_unlock(L); | 214 | lua_unlock(L); |
| 211 | } | 215 | } |
| 212 | 216 | ||
| 213 | 217 | ||
| 218 | LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) { | ||
| 219 | TValue *fr; | ||
| 220 | lua_lock(L); | ||
| 221 | fr = index2addr(L, fromidx); | ||
| 222 | api_checkvalidindex(L, fr); | ||
| 223 | moveto(L, fr, toidx); | ||
| 224 | lua_unlock(L); | ||
| 225 | } | ||
| 226 | |||
| 227 | |||
| 214 | LUA_API void lua_pushvalue (lua_State *L, int idx) { | 228 | LUA_API void lua_pushvalue (lua_State *L, int idx) { |
| 215 | lua_lock(L); | 229 | lua_lock(L); |
| 216 | setobj2s(L, L->top, index2addr(L, idx)); | 230 | setobj2s(L, L->top, index2addr(L, idx)); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.191 2009/09/18 18:58:45 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.192 2009/09/28 12:36:40 roberto Exp roberto $ |
| 3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -75,8 +75,8 @@ static int pushglobalfuncname (lua_State *L, lua_Debug *ar) { | |||
| 75 | lua_getinfo(L, "f", ar); /* push function */ | 75 | lua_getinfo(L, "f", ar); /* push function */ |
| 76 | lua_pushvalue(L, LUA_GLOBALSINDEX); /* push global table */ | 76 | lua_pushvalue(L, LUA_GLOBALSINDEX); /* push global table */ |
| 77 | if (findfield(L, top + 1, 2)) { | 77 | if (findfield(L, top + 1, 2)) { |
| 78 | lua_replace(L, top + 1); /* move name to proper place */ | 78 | lua_copy(L, -1, top + 1); /* move name to proper place */ |
| 79 | lua_pop(L, 1); /* remove other pushed value */ | 79 | lua_pop(L, 2); /* remove pushed values */ |
| 80 | return 1; | 80 | return 1; |
| 81 | } | 81 | } |
| 82 | else { | 82 | else { |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.217 2009/07/15 17:35:20 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.218 2009/08/04 18:20:18 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 | */ |
| @@ -432,8 +432,7 @@ static int luaB_xpcall (lua_State *L) { | |||
| 432 | int n = lua_gettop(L); | 432 | int n = lua_gettop(L); |
| 433 | luaL_argcheck(L, n >= 2, 2, "value expected"); | 433 | luaL_argcheck(L, n >= 2, 2, "value expected"); |
| 434 | lua_pushvalue(L, 1); /* exchange function... */ | 434 | lua_pushvalue(L, 1); /* exchange function... */ |
| 435 | lua_pushvalue(L, 2); /* ...and error handler */ | 435 | lua_copy(L, 2, 1); /* ...and error handler */ |
| 436 | lua_replace(L, 1); | ||
| 437 | lua_replace(L, 2); | 436 | lua_replace(L, 2); |
| 438 | status = lua_pcallk(L, n - 2, LUA_MULTRET, 1, 1, pcallcont); | 437 | status = lua_pcallk(L, n - 2, LUA_MULTRET, 1, 1, pcallcont); |
| 439 | luaL_checkstack(L, 1, NULL); | 438 | luaL_checkstack(L, 1, NULL); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: loadlib.c,v 1.64 2009/07/15 17:49:48 roberto Exp roberto $ | 2 | ** $Id: loadlib.c,v 1.65 2009/09/07 14:24:12 roberto Exp roberto $ |
| 3 | ** Dynamic library loader for Lua | 3 | ** Dynamic library loader for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | ** | 5 | ** |
| @@ -655,8 +655,7 @@ LUALIB_API int luaopen_package (lua_State *L) { | |||
| 655 | lua_setfield(L, -2, "__gc"); | 655 | lua_setfield(L, -2, "__gc"); |
| 656 | /* create `package' table */ | 656 | /* create `package' table */ |
| 657 | luaL_register(L, LUA_LOADLIBNAME, pk_funcs); | 657 | luaL_register(L, LUA_LOADLIBNAME, pk_funcs); |
| 658 | lua_pushvalue(L, -1); | 658 | lua_copy(L, -1, LUA_ENVIRONINDEX); |
| 659 | lua_replace(L, LUA_ENVIRONINDEX); | ||
| 660 | /* create `loaders' table */ | 659 | /* create `loaders' table */ |
| 661 | lua_createtable(L, sizeof(loaders)/sizeof(loaders[0]) - 1, 0); | 660 | lua_createtable(L, sizeof(loaders)/sizeof(loaders[0]) - 1, 0); |
| 662 | /* fill it with pre-defined loaders */ | 661 | /* fill it with pre-defined loaders */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.c,v 2.60 2009/09/28 13:50:19 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 2.61 2009/09/30 20:49:47 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 | */ |
| @@ -100,8 +100,7 @@ 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); /* remove f from stack */ | 101 | lua_remove(L, 1); /* remove f from stack */ |
| 102 | /* restore original environment for 'cpcall' */ | 102 | /* restore original environment for 'cpcall' */ |
| 103 | lua_pushvalue(L, LUA_GLOBALSINDEX); | 103 | lua_copy(L, LUA_GLOBALSINDEX, LUA_ENVIRONINDEX); |
| 104 | lua_replace(L, LUA_ENVIRONINDEX); | ||
| 105 | return f(L); | 104 | return f(L); |
| 106 | } | 105 | } |
| 107 | 106 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 2.73 2009/09/28 16:32:50 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.74 2009/09/30 20:49:25 roberto Exp roberto $ |
| 3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -971,6 +971,10 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) { | |||
| 971 | else if EQ("replace") { | 971 | else if EQ("replace") { |
| 972 | lua_replace(L1, getindex); | 972 | lua_replace(L1, getindex); |
| 973 | } | 973 | } |
| 974 | else if EQ("copy") { | ||
| 975 | int f = getindex; | ||
| 976 | lua_copy(L1, f, getindex); | ||
| 977 | } | ||
| 974 | else if EQ("gettable") { | 978 | else if EQ("gettable") { |
| 975 | lua_gettable(L1, getindex); | 979 | lua_gettable(L1, getindex); |
| 976 | } | 980 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.h,v 1.243 2009/09/17 18:04:21 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.244 2009/09/21 12:09:52 roberto Exp roberto $ |
| 3 | ** Lua - An Extensible Extension Language | 3 | ** Lua - An Extensible Extension Language |
| 4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) | 4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) |
| 5 | ** See Copyright Notice at the end of this file | 5 | ** See Copyright Notice at the end of this file |
| @@ -135,6 +135,7 @@ LUA_API void (lua_pushvalue) (lua_State *L, int idx); | |||
| 135 | LUA_API void (lua_remove) (lua_State *L, int idx); | 135 | LUA_API void (lua_remove) (lua_State *L, int idx); |
| 136 | LUA_API void (lua_insert) (lua_State *L, int idx); | 136 | LUA_API void (lua_insert) (lua_State *L, int idx); |
| 137 | LUA_API void (lua_replace) (lua_State *L, int idx); | 137 | LUA_API void (lua_replace) (lua_State *L, int idx); |
| 138 | LUA_API void (lua_copy) (lua_State *L, int fromidx, int toidx); | ||
| 138 | LUA_API int (lua_checkstack) (lua_State *L, int sz); | 139 | LUA_API int (lua_checkstack) (lua_State *L, int sz); |
| 139 | 140 | ||
| 140 | LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n); | 141 | LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n); |
