summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lapi.c48
-rw-r--r--ldblib.c11
-rw-r--r--lua.h4
3 files changed, 45 insertions, 18 deletions
diff --git a/lapi.c b/lapi.c
index 61a80085..ab3e92ff 100644
--- a/lapi.c
+++ b/lapi.c
@@ -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
631LUA_API void lua_rawgeti (lua_State *L, int idx, int n) { 631LUA_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
642LUA_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
743LUA_API void lua_rawseti (lua_State *L, int idx, int n) { 756LUA_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
769LUA_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}
diff --git a/ldblib.c b/ldblib.c
index 571f9773..35c47f81 100644
--- a/ldblib.c
+++ b/ldblib.c
@@ -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));
diff --git a/lua.h b/lua.h
index 349ef6ed..6e3ff629 100644
--- a/lua.h
+++ b/lua.h
@@ -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);
219LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k); 219LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k);
220LUA_API void (lua_rawget) (lua_State *L, int idx); 220LUA_API void (lua_rawget) (lua_State *L, int idx);
221LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n); 221LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n);
222LUA_API void (lua_rawgetp) (lua_State *L, int idx, const void *p);
222LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec); 223LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
223LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz); 224LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
224LUA_API int (lua_getmetatable) (lua_State *L, int objindex); 225LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
@@ -232,6 +233,7 @@ LUA_API void (lua_settable) (lua_State *L, int idx);
232LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k); 233LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
233LUA_API void (lua_rawset) (lua_State *L, int idx); 234LUA_API void (lua_rawset) (lua_State *L, int idx);
234LUA_API void (lua_rawseti) (lua_State *L, int idx, int n); 235LUA_API void (lua_rawseti) (lua_State *L, int idx, int n);
236LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p);
235LUA_API int (lua_setmetatable) (lua_State *L, int objindex); 237LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
236LUA_API void (lua_setuservalue) (lua_State *L, int idx); 238LUA_API void (lua_setuservalue) (lua_State *L, int idx);
237 239