diff options
-rw-r--r-- | lapi.c | 48 | ||||
-rw-r--r-- | ldblib.c | 11 | ||||
-rw-r--r-- | lua.h | 4 |
3 files changed, 45 insertions, 18 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.152 2011/09/26 20:17:27 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.153 2011/09/30 12:43:17 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 | */ |
@@ -629,11 +629,24 @@ LUA_API void lua_rawget (lua_State *L, int idx) { | |||
629 | 629 | ||
630 | 630 | ||
631 | LUA_API void lua_rawgeti (lua_State *L, int idx, int n) { | 631 | LUA_API void lua_rawgeti (lua_State *L, int idx, int n) { |
632 | StkId o; | 632 | StkId t; |
633 | lua_lock(L); | 633 | lua_lock(L); |
634 | o = index2addr(L, idx); | 634 | t = index2addr(L, idx); |
635 | api_check(L, ttistable(o), "table expected"); | 635 | api_check(L, ttistable(t), "table expected"); |
636 | setobj2s(L, L->top, luaH_getint(hvalue(o), n)); | 636 | setobj2s(L, L->top, luaH_getint(hvalue(t), n)); |
637 | api_incr_top(L); | ||
638 | lua_unlock(L); | ||
639 | } | ||
640 | |||
641 | |||
642 | LUA_API void lua_rawgetp (lua_State *L, int idx, const void *p) { | ||
643 | StkId t; | ||
644 | TValue k; | ||
645 | lua_lock(L); | ||
646 | t = index2addr(L, idx); | ||
647 | api_check(L, ttistable(t), "table expected"); | ||
648 | setpvalue(&k, cast(void *, p)); | ||
649 | setobj2s(L, L->top, luaH_get(hvalue(t), &k)); | ||
637 | api_incr_top(L); | 650 | api_incr_top(L); |
638 | lua_unlock(L); | 651 | lua_unlock(L); |
639 | } | 652 | } |
@@ -741,13 +754,28 @@ LUA_API void lua_rawset (lua_State *L, int idx) { | |||
741 | 754 | ||
742 | 755 | ||
743 | LUA_API void lua_rawseti (lua_State *L, int idx, int n) { | 756 | LUA_API void lua_rawseti (lua_State *L, int idx, int n) { |
744 | StkId o; | 757 | StkId t; |
745 | lua_lock(L); | 758 | lua_lock(L); |
746 | api_checknelems(L, 1); | 759 | api_checknelems(L, 1); |
747 | o = index2addr(L, idx); | 760 | t = index2addr(L, idx); |
748 | api_check(L, ttistable(o), "table expected"); | 761 | api_check(L, ttistable(t), "table expected"); |
749 | luaH_setint(L, hvalue(o), n, L->top - 1); | 762 | luaH_setint(L, hvalue(t), n, L->top - 1); |
750 | luaC_barrierback(L, gcvalue(o), L->top-1); | 763 | luaC_barrierback(L, gcvalue(t), L->top-1); |
764 | L->top--; | ||
765 | lua_unlock(L); | ||
766 | } | ||
767 | |||
768 | |||
769 | LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) { | ||
770 | StkId t; | ||
771 | TValue k; | ||
772 | lua_lock(L); | ||
773 | api_checknelems(L, 1); | ||
774 | t = index2addr(L, idx); | ||
775 | api_check(L, ttistable(t), "table expected"); | ||
776 | setpvalue(&k, cast(void *, p)); | ||
777 | setobj2t(L, luaH_set(L, hvalue(t), &k), L->top - 1); | ||
778 | luaC_barrierback(L, gcvalue(t), L->top - 1); | ||
751 | L->top--; | 779 | L->top--; |
752 | lua_unlock(L); | 780 | lua_unlock(L); |
753 | } | 781 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldblib.c,v 1.129 2011/01/26 16:30:02 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.130 2011/04/08 19:17:36 roberto Exp roberto $ |
3 | ** Interface from Lua to its debug API | 3 | ** Interface from Lua to its debug API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -260,8 +260,7 @@ static void hookf (lua_State *L, lua_Debug *ar) { | |||
260 | static const char *const hooknames[] = | 260 | static const char *const hooknames[] = |
261 | {"call", "return", "line", "count", "tail call"}; | 261 | {"call", "return", "line", "count", "tail call"}; |
262 | gethooktable(L); | 262 | gethooktable(L); |
263 | lua_pushlightuserdata(L, L); | 263 | lua_rawgetp(L, -1, L); |
264 | lua_rawget(L, -2); | ||
265 | if (lua_isfunction(L, -1)) { | 264 | if (lua_isfunction(L, -1)) { |
266 | lua_pushstring(L, hooknames[(int)ar->event]); | 265 | lua_pushstring(L, hooknames[(int)ar->event]); |
267 | if (ar->currentline >= 0) | 266 | if (ar->currentline >= 0) |
@@ -308,9 +307,8 @@ static int db_sethook (lua_State *L) { | |||
308 | func = hookf; mask = makemask(smask, count); | 307 | func = hookf; mask = makemask(smask, count); |
309 | } | 308 | } |
310 | gethooktable(L); | 309 | gethooktable(L); |
311 | lua_pushlightuserdata(L, L1); | ||
312 | lua_pushvalue(L, arg+1); | 310 | lua_pushvalue(L, arg+1); |
313 | lua_rawset(L, -3); /* set new hook */ | 311 | lua_rawsetp(L, -2, L1); /* set new hook */ |
314 | lua_pop(L, 1); /* remove hook table */ | 312 | lua_pop(L, 1); /* remove hook table */ |
315 | lua_sethook(L1, func, mask, count); /* set hooks */ | 313 | lua_sethook(L1, func, mask, count); /* set hooks */ |
316 | return 0; | 314 | return 0; |
@@ -327,8 +325,7 @@ static int db_gethook (lua_State *L) { | |||
327 | lua_pushliteral(L, "external hook"); | 325 | lua_pushliteral(L, "external hook"); |
328 | else { | 326 | else { |
329 | gethooktable(L); | 327 | gethooktable(L); |
330 | lua_pushlightuserdata(L, L1); | 328 | lua_rawgetp(L, -1, L1); /* get hook */ |
331 | lua_rawget(L, -2); /* get hook */ | ||
332 | lua_remove(L, -2); /* remove hook table */ | 329 | lua_remove(L, -2); /* remove hook table */ |
333 | } | 330 | } |
334 | lua_pushstring(L, unmakemask(mask, buff)); | 331 | lua_pushstring(L, unmakemask(mask, buff)); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.h,v 1.278 2011/07/02 16:00:15 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.279 2011/08/23 17:24:34 roberto Exp roberto $ |
3 | ** Lua - A Scripting Language | 3 | ** Lua - A Scripting 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 |
@@ -219,6 +219,7 @@ LUA_API void (lua_gettable) (lua_State *L, int idx); | |||
219 | LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k); | 219 | LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k); |
220 | LUA_API void (lua_rawget) (lua_State *L, int idx); | 220 | LUA_API void (lua_rawget) (lua_State *L, int idx); |
221 | LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n); | 221 | LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n); |
222 | LUA_API void (lua_rawgetp) (lua_State *L, int idx, const void *p); | ||
222 | LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec); | 223 | LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec); |
223 | LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz); | 224 | LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz); |
224 | LUA_API int (lua_getmetatable) (lua_State *L, int objindex); | 225 | LUA_API int (lua_getmetatable) (lua_State *L, int objindex); |
@@ -232,6 +233,7 @@ LUA_API void (lua_settable) (lua_State *L, int idx); | |||
232 | LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k); | 233 | LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k); |
233 | LUA_API void (lua_rawset) (lua_State *L, int idx); | 234 | LUA_API void (lua_rawset) (lua_State *L, int idx); |
234 | LUA_API void (lua_rawseti) (lua_State *L, int idx, int n); | 235 | LUA_API void (lua_rawseti) (lua_State *L, int idx, int n); |
236 | LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p); | ||
235 | LUA_API int (lua_setmetatable) (lua_State *L, int objindex); | 237 | LUA_API int (lua_setmetatable) (lua_State *L, int objindex); |
236 | LUA_API void (lua_setuservalue) (lua_State *L, int idx); | 238 | LUA_API void (lua_setuservalue) (lua_State *L, int idx); |
237 | 239 | ||