| 106 | |
| 107 | |
| 108 | void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { |
| 109 | int loop; |
| 110 | for (loop = 0; loop < MAXTAGLOOP; loop++) { |
| 111 | const TValue *tm; |
| 112 | if (ttistable(t)) { /* `t' is a table? */ |
| 113 | Table *h = hvalue(t); |
| 114 | const TValue *res = luaH_get(h, key); /* do a primitive get */ |
| 115 | if (!ttisnil(res) || /* result is no nil? */ |
| 116 | (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */ |
| 117 | setobj2s(L, val, res); |
| 118 | return; |
| 119 | } |
| 120 | /* else will try the tag method */ |
| 121 | } |
| 122 | else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) |
| 123 | luaG_typeerror(L, t, "index"); |
| 124 | if (ttisfunction(tm)) { |
| 125 | callTMres(L, val, tm, t, key); |
| 126 | return; |
| 127 | } |
| 128 | t = tm; /* else repeat with `tm' */ |
| 129 | } |
| 130 | luaG_runerror(L, "loop in gettable"); |
| 131 | } |
| 132 | |
| 133 | |
| 134 | void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) { |
no test coverage detected