diff options
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 32 |
1 files changed, 18 insertions, 14 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.155 2001/10/17 21:12:57 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.156 2001/10/17 21:17:45 roberto Exp $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -391,7 +391,7 @@ LUA_API void lua_getglobals (lua_State *L) { | |||
391 | 391 | ||
392 | LUA_API void lua_newtable (lua_State *L) { | 392 | LUA_API void lua_newtable (lua_State *L) { |
393 | lua_lock(L); | 393 | lua_lock(L); |
394 | sethvalue(L->top, luaH_new(L, 0)); | 394 | sethvalue(L->top, luaH_new(L, 0, 0)); |
395 | api_incr_top(L); | 395 | api_incr_top(L); |
396 | lua_unlock(L); | 396 | lua_unlock(L); |
397 | } | 397 | } |
@@ -647,22 +647,17 @@ LUA_API void lua_unref (lua_State *L, int ref) { | |||
647 | 647 | ||
648 | LUA_API int lua_next (lua_State *L, int index) { | 648 | LUA_API int lua_next (lua_State *L, int index) { |
649 | StkId t; | 649 | StkId t; |
650 | Node *n; | ||
651 | int more; | 650 | int more; |
652 | lua_lock(L); | 651 | lua_lock(L); |
653 | t = luaA_index(L, index); | 652 | t = luaA_index(L, index); |
654 | api_check(L, ttype(t) == LUA_TTABLE); | 653 | api_check(L, ttype(t) == LUA_TTABLE); |
655 | n = luaH_next(L, hvalue(t), luaA_index(L, -1)); | 654 | more = luaH_index(L, hvalue(t), luaA_index(L, -1)); |
656 | if (n) { | 655 | more = (luaH_nexti(hvalue(t), more, L->top - 1) != -1); |
657 | setobj(L->top-1, key(n)); | 656 | if (more) { |
658 | setobj(L->top, val(n)); | ||
659 | api_incr_top(L); | 657 | api_incr_top(L); |
660 | more = 1; | ||
661 | } | 658 | } |
662 | else { /* no more elements */ | 659 | else /* no more elements */ |
663 | L->top -= 1; /* remove key */ | 660 | L->top -= 1; /* remove key */ |
664 | more = 0; | ||
665 | } | ||
666 | lua_unlock(L); | 661 | lua_unlock(L); |
667 | return more; | 662 | return more; |
668 | } | 663 | } |
@@ -679,9 +674,18 @@ LUA_API int lua_getn (lua_State *L, int index) { | |||
679 | if (ttype(value) == LUA_TNUMBER) | 674 | if (ttype(value) == LUA_TNUMBER) |
680 | n = cast(int, nvalue(value)); | 675 | n = cast(int, nvalue(value)); |
681 | else { | 676 | else { |
677 | Node *nd; | ||
678 | Table *a = hvalue(t); | ||
682 | lua_Number max = 0; | 679 | lua_Number max = 0; |
683 | int i = hvalue(t)->size; | 680 | int i; |
684 | Node *nd = hvalue(t)->node; | 681 | i = sizearray(a); |
682 | while (i--) { | ||
683 | if (ttype(&a->array[i]) != LUA_TNIL) | ||
684 | break; | ||
685 | } | ||
686 | max = i+1; | ||
687 | i = sizenode(a); | ||
688 | nd = a->node; | ||
685 | while (i--) { | 689 | while (i--) { |
686 | if (ttype(key(nd)) == LUA_TNUMBER && | 690 | if (ttype(key(nd)) == LUA_TNUMBER && |
687 | ttype(val(nd)) != LUA_TNIL && | 691 | ttype(val(nd)) != LUA_TNIL && |
@@ -756,7 +760,7 @@ LUA_API int lua_getweakmode (lua_State *L, int index) { | |||
756 | LUA_API void lua_setweakmode (lua_State *L, int mode) { | 760 | LUA_API void lua_setweakmode (lua_State *L, int mode) { |
757 | lua_lock(L); | 761 | lua_lock(L); |
758 | api_check(L, ttype(L->top-1) == LUA_TTABLE); | 762 | api_check(L, ttype(L->top-1) == LUA_TTABLE); |
759 | hvalue(L->top-1)->weakmode = mode; | 763 | hvalue(L->top-1)->weakmode = cast(lu_byte, mode); |
760 | lua_unlock(L); | 764 | lua_unlock(L); |
761 | } | 765 | } |
762 | 766 | ||