| 133 | |
| 134 | |
| 135 | void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) { |
| 136 | int loop; |
| 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, *foundkey = NULL; |
| 142 | oldval = luaH_set_int(L, h, key, &foundkey); /* do a primitive set */ |
| 143 | if (!ttisnil(oldval) || /* result is no nil? */ |
| 144 | (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ |
| 145 | if (foundkey) { |
| 146 | if (ttype(foundkey) != ttype(key)) { |
| 147 | setobj2t(L, foundkey, key); |
| 148 | } else if (ttype(foundkey) == LUA_TUSERDATA) { |
| 149 | int f = luabb_dbtype_from_tvalue(foundkey); |
| 150 | int k = luabb_dbtype_from_tvalue(key); |
| 151 | if (f != k) { |
| 152 | setobj2t(L, foundkey, key); |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | setobj2t(L, oldval, val); |
| 157 | luaC_barriert(L, h, val); |
| 158 | return; |
| 159 | } |
| 160 | /* else will try the tag method */ |
| 161 | } |
| 162 | else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) |
| 163 | luaG_typeerror(L, t, "index"); |
| 164 | if (ttisfunction(tm)) { |
| 165 | callTM(L, tm, t, key, val); |
| 166 | return; |
| 167 | } |
| 168 | t = tm; /* else repeat with `tm' */ |
| 169 | } |
| 170 | luaG_runerror(L, "loop in settable"); |
| 171 | } |
| 172 | |
| 173 | |
| 174 | static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2, |
no test coverage detected