summaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-12-17 15:45:13 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-12-17 15:45:13 -0300
commitc646e57fd6307bd891e4e50ef5d6ee56b34e4cac (patch)
treee8f2d8a7bcb9f5c51ddc03f94f576f2fc6f43f06 /lapi.c
parente0ab13c62f2c1af0af955f173beb3ea6473e8064 (diff)
downloadlua-c646e57fd6307bd891e4e50ef5d6ee56b34e4cac.tar.gz
lua-c646e57fd6307bd891e4e50ef5d6ee56b34e4cac.tar.bz2
lua-c646e57fd6307bd891e4e50ef5d6ee56b34e4cac.zip
Joined common code in 'lua_rawset' and 'lua_rawsetp'
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/lapi.c b/lapi.c
index 8b48f7f5..b49d45c9 100644
--- a/lapi.c
+++ b/lapi.c
@@ -848,42 +848,39 @@ LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) {
848} 848}
849 849
850 850
851LUA_API void lua_rawset (lua_State *L, int idx) { 851static void aux_rawset (lua_State *L, int idx, TValue *key, int n) {
852 Table *t; 852 Table *t;
853 TValue *slot; 853 TValue *slot;
854 lua_lock(L); 854 lua_lock(L);
855 api_checknelems(L, 2); 855 api_checknelems(L, n);
856 t = gettable(L, idx); 856 t = gettable(L, idx);
857 slot = luaH_set(L, t, s2v(L->top - 2)); 857 slot = luaH_set(L, t, key);
858 setobj2t(L, slot, s2v(L->top - 1)); 858 setobj2t(L, slot, s2v(L->top - 1));
859 L->top -= n;
859 invalidateTMcache(t); 860 invalidateTMcache(t);
860 luaC_barrierback(L, obj2gco(t), s2v(L->top - 1)); 861 luaC_barrierback(L, obj2gco(t), s2v(L->top - 1));
861 L->top -= 2;
862 lua_unlock(L); 862 lua_unlock(L);
863} 863}
864 864
865 865
866LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) { 866LUA_API void lua_rawset (lua_State *L, int idx) {
867 Table *t; 867 aux_rawset(L, idx, s2v(L->top - 2), 2);
868 lua_lock(L);
869 api_checknelems(L, 1);
870 t = gettable(L, idx);
871 luaH_setint(L, t, n, s2v(L->top - 1));
872 luaC_barrierback(L, obj2gco(t), s2v(L->top - 1));
873 L->top--;
874 lua_unlock(L);
875} 868}
876 869
877 870
878LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) { 871LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) {
872 TValue k;
873 setpvalue(&k, cast_voidp(p));
874 aux_rawset(L, idx, &k, 1);
875}
876
877
878LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) {
879 Table *t; 879 Table *t;
880 TValue k, *slot;
881 lua_lock(L); 880 lua_lock(L);
882 api_checknelems(L, 1); 881 api_checknelems(L, 1);
883 t = gettable(L, idx); 882 t = gettable(L, idx);
884 setpvalue(&k, cast_voidp(p)); 883 luaH_setint(L, t, n, s2v(L->top - 1));
885 slot = luaH_set(L, t, &k);
886 setobj2t(L, slot, s2v(L->top - 1));
887 luaC_barrierback(L, obj2gco(t), s2v(L->top - 1)); 884 luaC_barrierback(L, obj2gco(t), s2v(L->top - 1));
888 L->top--; 885 L->top--;
889 lua_unlock(L); 886 lua_unlock(L);