MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / luaV_finishset

Function luaV_finishset

lib/lua/src/lvm.c:342–377  ·  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

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

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