MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / luaV_finishget

Function luaV_finishget

libraries/AP_Scripting/lua/src/lvm.c:164–197  ·  view source on GitHub ↗

** Finish the table access 'val = t[key]'. ** if 'slot' is NULL, 't' is not a table; otherwise, 'slot' points to ** t[k] entry (which must be nil). */

Source from the content-addressed store, hash-verified

162** t[k] entry (which must be nil).
163*/
164void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val,
165 const TValue *slot) {
166 int loop; /* counter to avoid infinite loops */
167 const TValue *tm; /* metamethod */
168 for (loop = 0; loop < MAXTAGLOOP; loop++) {
169 if (slot == NULL) { /* 't' is not a table? */
170 lua_assert(!ttistable(t));
171 tm = luaT_gettmbyobj(L, t, TM_INDEX);
172 if (ttisnil(tm))
173 luaG_typeerror(L, t, "index"); /* no metamethod */
174 /* else will try the metamethod */
175 }
176 else { /* 't' is a table */
177 lua_assert(ttisnil(slot));
178 tm = fasttm(L, hvalue(t)->metatable, TM_INDEX); /* table's metamethod */
179 if (tm == NULL) { /* no metamethod? */
180 setnilvalue(val); /* result is nil */
181 return;
182 }
183 /* else will try the metamethod */
184 }
185 if (ttisfunction(tm)) { /* is metamethod a function? */
186 luaT_callTM(L, tm, t, key, val, 1); /* call it */
187 return;
188 }
189 t = tm; /* else try to access 'tm[key]' */
190 if (luaV_fastget(L,t,key,slot,luaH_get)) { /* fast track? */
191 setobj2s(L, val, slot); /* done */
192 return;
193 }
194 /* else repeat (tail call 'luaV_finishget') */
195 }
196 luaG_runerror(L, "'__index' chain too long; possible loop");
197}
198
199
200/*

Callers 3

luaV_executeFunction · 0.85
auxgetstrFunction · 0.85
lua_getiFunction · 0.85

Calls 4

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

Tested by

no test coverage detected