aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-05-16 14:55:49 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-05-16 14:55:49 -0300
commitf8d30826dda6ee8e99200de57a1997734b853db2 (patch)
treed3a24665802f41fe3216714252ed189006f302cd /lapi.c
parent351ccd733298e08c41937c1baf22a68e62bfeca9 (diff)
downloadlua-f8d30826dda6ee8e99200de57a1997734b853db2.tar.gz
lua-f8d30826dda6ee8e99200de57a1997734b853db2.tar.bz2
lua-f8d30826dda6ee8e99200de57a1997734b853db2.zip
New table API for 'set' functions
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/lapi.c b/lapi.c
index 2e27bc92..97a9f272 100644
--- a/lapi.c
+++ b/lapi.c
@@ -823,17 +823,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) 823** t[k] = value at the top of the stack (where 'k' is a string)
824*/ 824*/
825static void auxsetstr (lua_State *L, const TValue *t, const char *k) { 825static void auxsetstr (lua_State *L, const TValue *t, const char *k) {
826 const TValue *slot; 826 int aux;
827 TString *str = luaS_new(L, k); 827 TString *str = luaS_new(L, k);
828 api_checknelems(L, 1); 828 api_checknelems(L, 1);
829 if (luaV_fastget(L, t, str, slot, luaH_getstr)) { 829 luaV_fastset1(t, str, s2v(L->top.p - 1), aux, luaH_setstr1);
830 luaV_finishfastset(L, t, slot, s2v(L->top.p - 1)); 830 if (aux == HOK) {
831 luaV_finishfastset1(L, t, s2v(L->top.p - 1));
831 L->top.p--; /* pop value */ 832 L->top.p--; /* pop value */
832 } 833 }
833 else { 834 else {
834 setsvalue2s(L, L->top.p, str); /* push 'str' (to make it a TValue) */ 835 setsvalue2s(L, L->top.p, str); /* push 'str' (to make it a TValue) */
835 api_incr_top(L); 836 api_incr_top(L);
836 luaV_finishset(L, t, s2v(L->top.p - 1), s2v(L->top.p - 2), slot); 837 luaV_finishset1(L, t, s2v(L->top.p - 1), s2v(L->top.p - 2), aux);
837 L->top.p -= 2; /* pop value and key */ 838 L->top.p -= 2; /* pop value and key */
838 } 839 }
839 lua_unlock(L); /* lock done by caller */ 840 lua_unlock(L); /* lock done by caller */
@@ -850,15 +851,16 @@ LUA_API void lua_setglobal (lua_State *L, const char *name) {
850 851
851LUA_API void lua_settable (lua_State *L, int idx) { 852LUA_API void lua_settable (lua_State *L, int idx) {
852 TValue *t; 853 TValue *t;
853 const TValue *slot; 854 int aux;
854 lua_lock(L); 855 lua_lock(L);
855 api_checknelems(L, 2); 856 api_checknelems(L, 2);
856 t = index2value(L, idx); 857 t = index2value(L, idx);
857 if (luaV_fastget(L, t, s2v(L->top.p - 2), slot, luaH_get)) { 858 luaV_fastset1(t, s2v(L->top.p - 2), s2v(L->top.p - 1), aux, luaH_set1);
858 luaV_finishfastset(L, t, slot, s2v(L->top.p - 1)); 859 if (aux == HOK) {
860 luaV_finishfastset1(L, t, s2v(L->top.p - 1));
859 } 861 }
860 else 862 else
861 luaV_finishset(L, t, s2v(L->top.p - 2), s2v(L->top.p - 1), slot); 863 luaV_finishset1(L, t, s2v(L->top.p - 2), s2v(L->top.p - 1), aux);
862 L->top.p -= 2; /* pop index and value */ 864 L->top.p -= 2; /* pop index and value */
863 lua_unlock(L); 865 lua_unlock(L);
864} 866}
@@ -872,17 +874,18 @@ LUA_API void lua_setfield (lua_State *L, int idx, const char *k) {
872 874
873LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) { 875LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) {
874 TValue *t; 876 TValue *t;
875 const TValue *slot; 877 int aux;
876 lua_lock(L); 878 lua_lock(L);
877 api_checknelems(L, 1); 879 api_checknelems(L, 1);
878 t = index2value(L, idx); 880 t = index2value(L, idx);
879 if (luaV_fastgeti(L, t, n, slot)) { 881 luaV_fastseti1(t, n, s2v(L->top.p - 1), aux);
880 luaV_finishfastset(L, t, slot, s2v(L->top.p - 1)); 882 if (aux == HOK) {
883 luaV_finishfastset1(L, t, s2v(L->top.p - 1));
881 } 884 }
882 else { 885 else {
883 TValue aux; 886 TValue temp;
884 setivalue(&aux, n); 887 setivalue(&temp, n);
885 luaV_finishset(L, t, &aux, s2v(L->top.p - 1), slot); 888 luaV_finishset1(L, t, &temp, s2v(L->top.p - 1), aux);
886 } 889 }
887 L->top.p--; /* pop value */ 890 L->top.p--; /* pop value */
888 lua_unlock(L); 891 lua_unlock(L);