MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / luaV_settable

Function luaV_settable

third-party/lua-5.2.4/src/lvm.c:136–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134
135
136void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
137 int loop;
138 for (loop = 0; loop < MAXTAGLOOP; loop++) {
139 const TValue *tm;
140 if (ttistable(t)) { /* `t' is a table? */
141 Table *h = hvalue(t);
142 TValue *oldval = cast(TValue *, luaH_get(h, key));
143 /* if previous value is not nil, there must be a previous entry
144 in the table; moreover, a metamethod has no relevance */
145 if (!ttisnil(oldval) ||
146 /* previous value is nil; must check the metamethod */
147 ((tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL &&
148 /* no metamethod; is there a previous entry in the table? */
149 (oldval != luaO_nilobject ||
150 /* no previous entry; must create one. (The next test is
151 always true; we only need the assignment.) */
152 (oldval = luaH_newkey(L, h, key), 1)))) {
153 /* no metamethod and (now) there is an entry with given key */
154 setobj2t(L, oldval, val); /* assign new value to that entry */
155 invalidateTMcache(h);
156 luaC_barrierback(L, obj2gco(h), val);
157 return;
158 }
159 /* else will try the metamethod */
160 }
161 else /* not a table; check metamethod */
162 if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))
163 luaG_typeerror(L, t, "index");
164 /* there is a metamethod */
165 if (ttisfunction(tm)) {
166 callTM(L, tm, t, key, val, 0);
167 return;
168 }
169 t = tm; /* else repeat with 'tm' */
170 }
171 luaG_runerror(L, "loop in settable");
172}
173
174
175static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2,

Callers 4

luaV_executeFunction · 0.70
lua_setglobalFunction · 0.70
lua_settableFunction · 0.70
lua_setfieldFunction · 0.70

Calls 7

luaC_barrierbackFunction · 0.85
luaH_getFunction · 0.70
luaH_newkeyFunction · 0.70
luaT_gettmbyobjFunction · 0.70
luaG_typeerrorFunction · 0.70
callTMFunction · 0.70
luaG_runerrorFunction · 0.70

Tested by

no test coverage detected