diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-05-16 16:53:29 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-05-16 16:53:29 -0300 |
| commit | 819bd51d87b799fdee029754c660dc9a5587ef57 (patch) | |
| tree | 0b1ffb9a3fd591372992c72a27e4590b48236b71 /lapi.c | |
| parent | f8d30826dda6ee8e99200de57a1997734b853db2 (diff) | |
| download | lua-819bd51d87b799fdee029754c660dc9a5587ef57.tar.gz lua-819bd51d87b799fdee029754c660dc9a5587ef57.tar.bz2 lua-819bd51d87b799fdee029754c660dc9a5587ef57.zip | |
Some cleaning in the new table API
Diffstat (limited to 'lapi.c')
| -rw-r--r-- | lapi.c | 70 |
1 files changed, 34 insertions, 36 deletions
| @@ -637,16 +637,16 @@ LUA_API int lua_pushthread (lua_State *L) { | |||
| 637 | 637 | ||
| 638 | 638 | ||
| 639 | l_sinline int auxgetstr (lua_State *L, const TValue *t, const char *k) { | 639 | l_sinline int auxgetstr (lua_State *L, const TValue *t, const char *k) { |
| 640 | int aux; | 640 | int hres; |
| 641 | TString *str = luaS_new(L, k); | 641 | TString *str = luaS_new(L, k); |
| 642 | luaV_fastget1(t, str, s2v(L->top.p), luaH_getstr1, aux); | 642 | luaV_fastget(t, str, s2v(L->top.p), luaH_getstr, hres); |
| 643 | if (aux == HOK) { | 643 | if (hres == HOK) { |
| 644 | api_incr_top(L); | 644 | api_incr_top(L); |
| 645 | } | 645 | } |
| 646 | else { | 646 | else { |
| 647 | setsvalue2s(L, L->top.p, str); | 647 | setsvalue2s(L, L->top.p, str); |
| 648 | api_incr_top(L); | 648 | api_incr_top(L); |
| 649 | luaV_finishget1(L, t, s2v(L->top.p - 1), L->top.p - 1, aux); | 649 | luaV_finishget(L, t, s2v(L->top.p - 1), L->top.p - 1, hres); |
| 650 | } | 650 | } |
| 651 | lua_unlock(L); | 651 | lua_unlock(L); |
| 652 | return ttype(s2v(L->top.p - 1)); | 652 | return ttype(s2v(L->top.p - 1)); |
| @@ -672,13 +672,13 @@ LUA_API int lua_getglobal (lua_State *L, const char *name) { | |||
| 672 | 672 | ||
| 673 | 673 | ||
| 674 | LUA_API int lua_gettable (lua_State *L, int idx) { | 674 | LUA_API int lua_gettable (lua_State *L, int idx) { |
| 675 | int aux; | 675 | int hres; |
| 676 | TValue *t; | 676 | TValue *t; |
| 677 | lua_lock(L); | 677 | lua_lock(L); |
| 678 | t = index2value(L, idx); | 678 | t = index2value(L, idx); |
| 679 | luaV_fastget1(t, s2v(L->top.p - 1), s2v(L->top.p - 1), luaH_get1, aux); | 679 | luaV_fastget(t, s2v(L->top.p - 1), s2v(L->top.p - 1), luaH_get, hres); |
| 680 | if (aux != HOK) | 680 | if (hres != HOK) |
| 681 | luaV_finishget1(L, t, s2v(L->top.p - 1), L->top.p - 1, aux); | 681 | luaV_finishget(L, t, s2v(L->top.p - 1), L->top.p - 1, hres); |
| 682 | lua_unlock(L); | 682 | lua_unlock(L); |
| 683 | return ttype(s2v(L->top.p - 1)); | 683 | return ttype(s2v(L->top.p - 1)); |
| 684 | } | 684 | } |
| @@ -692,14 +692,14 @@ LUA_API int lua_getfield (lua_State *L, int idx, const char *k) { | |||
| 692 | 692 | ||
| 693 | LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { | 693 | LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { |
| 694 | TValue *t; | 694 | TValue *t; |
| 695 | int aux; | 695 | int hres; |
| 696 | lua_lock(L); | 696 | lua_lock(L); |
| 697 | t = index2value(L, idx); | 697 | t = index2value(L, idx); |
| 698 | luaV_fastgeti1(t, n, s2v(L->top.p), aux); | 698 | luaV_fastgeti(t, n, s2v(L->top.p), hres); |
| 699 | if (aux != HOK) { | 699 | if (hres != HOK) { |
| 700 | TValue key; | 700 | TValue key; |
| 701 | setivalue(&key, n); | 701 | setivalue(&key, n); |
| 702 | luaV_finishget1(L, t, &key, L->top.p, aux); | 702 | luaV_finishget(L, t, &key, L->top.p, hres); |
| 703 | } | 703 | } |
| 704 | api_incr_top(L); | 704 | api_incr_top(L); |
| 705 | lua_unlock(L); | 705 | lua_unlock(L); |
| @@ -707,11 +707,9 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { | |||
| 707 | } | 707 | } |
| 708 | 708 | ||
| 709 | 709 | ||
| 710 | l_sinline int finishrawget (lua_State *L, const TValue *val) { | 710 | l_sinline int finishrawget (lua_State *L, int hres) { |
| 711 | if (isempty(val)) /* avoid copying empty items to the stack */ | 711 | if (hres != HOK) /* avoid copying empty items to the stack */ |
| 712 | setnilvalue(s2v(L->top.p)); | 712 | setnilvalue(s2v(L->top.p)); |
| 713 | else | ||
| 714 | setobj2s(L, L->top.p, val); | ||
| 715 | api_incr_top(L); | 713 | api_incr_top(L); |
| 716 | lua_unlock(L); | 714 | lua_unlock(L); |
| 717 | return ttype(s2v(L->top.p - 1)); | 715 | return ttype(s2v(L->top.p - 1)); |
| @@ -727,13 +725,13 @@ static Table *gettable (lua_State *L, int idx) { | |||
| 727 | 725 | ||
| 728 | LUA_API int lua_rawget (lua_State *L, int idx) { | 726 | LUA_API int lua_rawget (lua_State *L, int idx) { |
| 729 | Table *t; | 727 | Table *t; |
| 730 | const TValue *val; | 728 | int hres; |
| 731 | lua_lock(L); | 729 | lua_lock(L); |
| 732 | api_checknelems(L, 1); | 730 | api_checknelems(L, 1); |
| 733 | t = gettable(L, idx); | 731 | t = gettable(L, idx); |
| 734 | val = luaH_get(t, s2v(L->top.p - 1)); | 732 | hres = luaH_get(t, s2v(L->top.p - 1), s2v(L->top.p - 1)); |
| 735 | L->top.p--; /* remove key */ | 733 | L->top.p--; /* remove key */ |
| 736 | return finishrawget(L, val); | 734 | return finishrawget(L, hres); |
| 737 | } | 735 | } |
| 738 | 736 | ||
| 739 | 737 | ||
| @@ -741,7 +739,7 @@ LUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) { | |||
| 741 | Table *t; | 739 | Table *t; |
| 742 | lua_lock(L); | 740 | lua_lock(L); |
| 743 | t = gettable(L, idx); | 741 | t = gettable(L, idx); |
| 744 | return finishrawget(L, luaH_getint(t, n)); | 742 | return finishrawget(L, luaH_getint(t, n, s2v(L->top.p))); |
| 745 | } | 743 | } |
| 746 | 744 | ||
| 747 | 745 | ||
| @@ -751,7 +749,7 @@ LUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) { | |||
| 751 | lua_lock(L); | 749 | lua_lock(L); |
| 752 | t = gettable(L, idx); | 750 | t = gettable(L, idx); |
| 753 | setpvalue(&k, cast_voidp(p)); | 751 | setpvalue(&k, cast_voidp(p)); |
| 754 | return finishrawget(L, luaH_get(t, &k)); | 752 | return finishrawget(L, luaH_get(t, &k, s2v(L->top.p))); |
| 755 | } | 753 | } |
| 756 | 754 | ||
| 757 | 755 | ||
| @@ -823,18 +821,18 @@ LUA_API int lua_getiuservalue (lua_State *L, int idx, int n) { | |||
| 823 | ** t[k] = value at the top of the stack (where 'k' is a string) | 821 | ** t[k] = value at the top of the stack (where 'k' is a string) |
| 824 | */ | 822 | */ |
| 825 | static void auxsetstr (lua_State *L, const TValue *t, const char *k) { | 823 | static void auxsetstr (lua_State *L, const TValue *t, const char *k) { |
| 826 | int aux; | 824 | int hres; |
| 827 | TString *str = luaS_new(L, k); | 825 | TString *str = luaS_new(L, k); |
| 828 | api_checknelems(L, 1); | 826 | api_checknelems(L, 1); |
| 829 | luaV_fastset1(t, str, s2v(L->top.p - 1), aux, luaH_setstr1); | 827 | luaV_fastset(t, str, s2v(L->top.p - 1), hres, luaH_psetstr); |
| 830 | if (aux == HOK) { | 828 | if (hres == HOK) { |
| 831 | luaV_finishfastset1(L, t, s2v(L->top.p - 1)); | 829 | luaV_finishfastset(L, t, s2v(L->top.p - 1)); |
| 832 | L->top.p--; /* pop value */ | 830 | L->top.p--; /* pop value */ |
| 833 | } | 831 | } |
| 834 | else { | 832 | else { |
| 835 | setsvalue2s(L, L->top.p, str); /* push 'str' (to make it a TValue) */ | 833 | setsvalue2s(L, L->top.p, str); /* push 'str' (to make it a TValue) */ |
| 836 | api_incr_top(L); | 834 | api_incr_top(L); |
| 837 | luaV_finishset1(L, t, s2v(L->top.p - 1), s2v(L->top.p - 2), aux); | 835 | luaV_finishset(L, t, s2v(L->top.p - 1), s2v(L->top.p - 2), hres); |
| 838 | L->top.p -= 2; /* pop value and key */ | 836 | L->top.p -= 2; /* pop value and key */ |
| 839 | } | 837 | } |
| 840 | lua_unlock(L); /* lock done by caller */ | 838 | lua_unlock(L); /* lock done by caller */ |
| @@ -851,16 +849,16 @@ LUA_API void lua_setglobal (lua_State *L, const char *name) { | |||
| 851 | 849 | ||
| 852 | LUA_API void lua_settable (lua_State *L, int idx) { | 850 | LUA_API void lua_settable (lua_State *L, int idx) { |
| 853 | TValue *t; | 851 | TValue *t; |
| 854 | int aux; | 852 | int hres; |
| 855 | lua_lock(L); | 853 | lua_lock(L); |
| 856 | api_checknelems(L, 2); | 854 | api_checknelems(L, 2); |
| 857 | t = index2value(L, idx); | 855 | t = index2value(L, idx); |
| 858 | luaV_fastset1(t, s2v(L->top.p - 2), s2v(L->top.p - 1), aux, luaH_set1); | 856 | luaV_fastset(t, s2v(L->top.p - 2), s2v(L->top.p - 1), hres, luaH_pset); |
| 859 | if (aux == HOK) { | 857 | if (hres == HOK) { |
| 860 | luaV_finishfastset1(L, t, s2v(L->top.p - 1)); | 858 | luaV_finishfastset(L, t, s2v(L->top.p - 1)); |
| 861 | } | 859 | } |
| 862 | else | 860 | else |
| 863 | luaV_finishset1(L, t, s2v(L->top.p - 2), s2v(L->top.p - 1), aux); | 861 | luaV_finishset(L, t, s2v(L->top.p - 2), s2v(L->top.p - 1), hres); |
| 864 | L->top.p -= 2; /* pop index and value */ | 862 | L->top.p -= 2; /* pop index and value */ |
| 865 | lua_unlock(L); | 863 | lua_unlock(L); |
| 866 | } | 864 | } |
| @@ -874,18 +872,18 @@ LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { | |||
| 874 | 872 | ||
| 875 | LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) { | 873 | LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) { |
| 876 | TValue *t; | 874 | TValue *t; |
| 877 | int aux; | 875 | int hres; |
| 878 | lua_lock(L); | 876 | lua_lock(L); |
| 879 | api_checknelems(L, 1); | 877 | api_checknelems(L, 1); |
| 880 | t = index2value(L, idx); | 878 | t = index2value(L, idx); |
| 881 | luaV_fastseti1(t, n, s2v(L->top.p - 1), aux); | 879 | luaV_fastseti(t, n, s2v(L->top.p - 1), hres); |
| 882 | if (aux == HOK) { | 880 | if (hres == HOK) { |
| 883 | luaV_finishfastset1(L, t, s2v(L->top.p - 1)); | 881 | luaV_finishfastset(L, t, s2v(L->top.p - 1)); |
| 884 | } | 882 | } |
| 885 | else { | 883 | else { |
| 886 | TValue temp; | 884 | TValue temp; |
| 887 | setivalue(&temp, n); | 885 | setivalue(&temp, n); |
| 888 | luaV_finishset1(L, t, &temp, s2v(L->top.p - 1), aux); | 886 | luaV_finishset(L, t, &temp, s2v(L->top.p - 1), hres); |
| 889 | } | 887 | } |
| 890 | L->top.p--; /* pop value */ | 888 | L->top.p--; /* pop value */ |
| 891 | lua_unlock(L); | 889 | lua_unlock(L); |
