| 132 | |
| 133 | |
| 134 | void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) { |
| 135 | int loop; |
| 136 | TValue temp; |
| 137 | for (loop = 0; loop < MAXTAGLOOP; loop++) { |
| 138 | const TValue *tm; |
| 139 | if (ttistable(t)) { /* `t' is a table? */ |
| 140 | Table *h = hvalue(t); |
| 141 | TValue *oldval = luaH_set(L, h, key); /* do a primitive set */ |
| 142 | if (!ttisnil(oldval) || /* result is no nil? */ |
| 143 | (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ |
| 144 | setobj2t(L, oldval, val); |
| 145 | h->flags = 0; |
| 146 | luaC_barriert(L, h, val); |
| 147 | return; |
| 148 | } |
| 149 | /* else will try the tag method */ |
| 150 | } |
| 151 | else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) |
| 152 | luaG_typeerror(L, t, "index"); |
| 153 | if (ttisfunction(tm)) { |
| 154 | callTM(L, tm, t, key, val); |
| 155 | return; |
| 156 | } |
| 157 | /* else repeat with `tm' */ |
| 158 | setobj(L, &temp, tm); /* avoid pointing inside table (may rehash) */ |
| 159 | t = &temp; |
| 160 | } |
| 161 | luaG_runerror(L, "loop in settable"); |
| 162 | } |
| 163 | |
| 164 | |
| 165 | static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2, |
no test coverage detected