MCPcopy Create free account
hub / github.com/axmolengine/axmol / luaV_finishset

Function luaV_finishset

3rdparty/lua/plainlua/lvm.c:332–370  ·  view source on GitHub ↗

** Finish a table assignment 't[key] = val'. ** If 'slot' is NULL, 't' is not a table. Otherwise, 'slot' points ** to the entry 't[key]', or to a value with an absent key if there ** is no such entry. (The value at 'slot' must be empty, otherwise ** 'luaV_fastget' would have done the job.) */

Source from the content-addressed store, hash-verified

330** 'luaV_fastget' would have done the job.)
331*/
332void luaV_finishset (lua_State *L, const TValue *t, TValue *key,
333 TValue *val, const TValue *slot) {
334 int loop; /* counter to avoid infinite loops */
335 for (loop = 0; loop < MAXTAGLOOP; loop++) {
336 const TValue *tm; /* '__newindex' metamethod */
337 if (slot != NULL) { /* is 't' a table? */
338 Table *h = hvalue(t); /* save 't' table */
339 lua_assert(isempty(slot)); /* slot must be empty */
340 tm = fasttm(L, h->metatable, TM_NEWINDEX); /* get metamethod */
341 if (tm == NULL) { /* no metamethod? */
342 sethvalue2s(L, L->top.p, h); /* anchor 't' */
343 L->top.p++; /* assume EXTRA_STACK */
344 luaH_finishset(L, h, key, slot, val); /* set new value */
345 L->top.p--;
346 invalidateTMcache(h);
347 luaC_barrierback(L, obj2gco(h), val);
348 return;
349 }
350 /* else will try the metamethod */
351 }
352 else { /* not a table; check metamethod */
353 tm = luaT_gettmbyobj(L, t, TM_NEWINDEX);
354 if (l_unlikely(notm(tm)))
355 luaG_typeerror(L, t, "index");
356 }
357 /* try the metamethod */
358 if (ttisfunction(tm)) {
359 luaT_callTM(L, tm, t, key, val);
360 return;
361 }
362 t = tm; /* else repeat assignment over 'tm' */
363 if (luaV_fastget(L, t, key, slot, luaH_get)) {
364 luaV_finishfastset(L, t, slot, val);
365 return; /* done */
366 }
367 /* else 'return luaV_finishset(L, t, key, val, slot)' (loop) */
368 }
369 luaG_runerror(L, "'__newindex' chain too long; possible loop");
370}
371
372
373/*

Callers 4

luaV_executeFunction · 0.85
auxsetstrFunction · 0.85
lua_settableFunction · 0.85
lua_setiFunction · 0.85

Calls 5

luaH_finishsetFunction · 0.85
luaT_gettmbyobjFunction · 0.85
luaG_typeerrorFunction · 0.85
luaT_callTMFunction · 0.85
luaG_runerrorFunction · 0.85

Tested by

no test coverage detected