** Finish a raw "set table" operation, where 'hres' encodes where the ** value should have been (the result of a previous 'pset' operation). ** Beware: when using this function the caller probably need to check a ** GC barrier and invalidate the TM cache. */
| 1152 | ** GC barrier and invalidate the TM cache. |
| 1153 | */ |
| 1154 | void luaH_finishset (lua_State *L, Table *t, const TValue *key, |
| 1155 | TValue *value, int hres) { |
| 1156 | lua_assert(hres != HOK); |
| 1157 | if (hres == HNOTFOUND) { |
| 1158 | TValue aux; |
| 1159 | if (l_unlikely(ttisnil(key))) |
| 1160 | luaG_runerror(L, "table index is nil"); |
| 1161 | else if (ttisfloat(key)) { |
| 1162 | lua_Number f = fltvalue(key); |
| 1163 | lua_Integer k; |
| 1164 | if (luaV_flttointeger(f, &k, F2Ieq)) { |
| 1165 | setivalue(&aux, k); /* key is equal to an integer */ |
| 1166 | key = &aux; /* insert it as an integer */ |
| 1167 | } |
| 1168 | else if (l_unlikely(luai_numisnan(f))) |
| 1169 | luaG_runerror(L, "table index is NaN"); |
| 1170 | } |
| 1171 | else if (isextstr(key)) { /* external string? */ |
| 1172 | /* If string is short, must internalize it to be used as table key */ |
| 1173 | TString *ts = luaS_normstr(L, tsvalue(key)); |
| 1174 | setsvalue2s(L, L->top.p++, ts); /* anchor 'ts' (EXTRA_STACK) */ |
| 1175 | luaH_newkey(L, t, s2v(L->top.p - 1), value); |
| 1176 | L->top.p--; |
| 1177 | return; |
| 1178 | } |
| 1179 | luaH_newkey(L, t, key, value); |
| 1180 | } |
| 1181 | else if (hres > 0) { /* regular Node? */ |
| 1182 | setobj2t(L, gval(gnode(t, hres - HFIRSTNODE)), value); |
| 1183 | } |
| 1184 | else { /* array entry */ |
| 1185 | hres = ~hres; /* real index */ |
| 1186 | obj2arr(t, cast_uint(hres), value); |
| 1187 | } |
| 1188 | } |
| 1189 | |
| 1190 | |
| 1191 | /* |
no test coverage detected