aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-04-11 11:42:41 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-04-11 11:42:41 -0300
commit0e0e4a480e6d9b0125a96ca982a3e9571578a037 (patch)
tree21f13f032e9e337879168c74871d0d4bb2534248 /lapi.c
parent2a501882692afaa08ecc38af3052e9b4f60f6e85 (diff)
downloadlua-0e0e4a480e6d9b0125a96ca982a3e9571578a037.tar.gz
lua-0e0e4a480e6d9b0125a96ca982a3e9571578a037.tar.bz2
lua-0e0e4a480e6d9b0125a96ca982a3e9571578a037.zip
first implementation for weak tables
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/lapi.c b/lapi.c
index 6652e7f4..f146bf8a 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.136 2001/03/07 18:09:25 roberto Exp roberto $ 2** $Id: lapi.c,v 1.137 2001/03/26 14:31:49 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*/
@@ -681,18 +681,19 @@ LUA_API int lua_next (lua_State *L, int index) {
681 681
682 682
683LUA_API int lua_getn (lua_State *L, int index) { 683LUA_API int lua_getn (lua_State *L, int index) {
684 Hash *h; 684 StkId t;
685 const TObject *value; 685 const TObject *value;
686 int n; 686 int n;
687 lua_lock(L); 687 lua_lock(L);
688 h = hvalue(luaA_index(L, index)); 688 t = luaA_index(L, index);
689 value = luaH_getstr(h, luaS_newliteral(L, l_s("n"))); /* = h.n */ 689 api_check(L, ttype(t) == LUA_TTABLE);
690 value = luaH_getstr(hvalue(t), luaS_newliteral(L, l_s("n"))); /* = t.n */
690 if (ttype(value) == LUA_TNUMBER) 691 if (ttype(value) == LUA_TNUMBER)
691 n = (int)nvalue(value); 692 n = (int)nvalue(value);
692 else { 693 else {
693 lua_Number max = 0; 694 lua_Number max = 0;
694 int i = h->size; 695 int i = hvalue(t)->size;
695 Node *nd = h->node; 696 Node *nd = hvalue(t)->node;
696 while (i--) { 697 while (i--) {
697 if (ttype_key(nd) == LUA_TNUMBER && 698 if (ttype_key(nd) == LUA_TNUMBER &&
698 ttype(val(nd)) != LUA_TNIL && 699 ttype(val(nd)) != LUA_TNIL &&
@@ -737,3 +738,23 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size) {
737 return p; 738 return p;
738} 739}
739 740
741
742LUA_API int lua_getweakmode (lua_State *L, int index) {
743 StkId t;
744 int mode;
745 lua_lock(L);
746 t = luaA_index(L, index);
747 api_check(L, ttype(t) == LUA_TTABLE);
748 mode = hvalue(t)->weakmode;
749 lua_unlock(L);
750 return mode;
751}
752
753
754LUA_API void lua_setweakmode (lua_State *L, int mode) {
755 lua_lock(L);
756 api_check(L, ttype(L->top-1) == LUA_TTABLE);
757 hvalue(L->top-1)->weakmode = mode;
758 lua_unlock(L);
759}
760