diff options
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 33 |
1 files changed, 27 insertions, 6 deletions
@@ -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 | ||
683 | LUA_API int lua_getn (lua_State *L, int index) { | 683 | LUA_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 | |||
742 | LUA_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 | |||
754 | LUA_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 | |||