| 1096 | */ |
| 1097 | |
| 1098 | int luaH_psetshortstr (Table *t, TString *key, TValue *val) { |
| 1099 | const TValue *slot = luaH_Hgetshortstr(t, key); |
| 1100 | if (!ttisnil(slot)) { /* key already has a value? (all too common) */ |
| 1101 | setobj(((lua_State*)NULL), cast(TValue*, slot), val); /* update it */ |
| 1102 | return HOK; /* done */ |
| 1103 | } |
| 1104 | else if (checknoTM(t->metatable, TM_NEWINDEX)) { /* no metamethod? */ |
| 1105 | if (ttisnil(val)) /* new value is nil? */ |
| 1106 | return HOK; /* done (value is already nil/absent) */ |
| 1107 | if (isabstkey(slot) && /* key is absent? */ |
| 1108 | !(isblack(t) && iswhite(key))) { /* and don't need barrier? */ |
| 1109 | TValue tk; /* key as a TValue */ |
| 1110 | setsvalue(cast(lua_State *, NULL), &tk, key); |
| 1111 | if (insertkey(t, &tk, val)) { /* insert key, if there is space */ |
| 1112 | invalidateTMcache(t); |
| 1113 | return HOK; |
| 1114 | } |
| 1115 | } |
| 1116 | } |
| 1117 | /* Else, either table has new-index metamethod, or it needs barrier, |
| 1118 | or it needs to rehash for the new key. In any of these cases, the |
| 1119 | operation cannot be completed here. Return a code for the caller. */ |
| 1120 | return retpsetcode(t, slot); |
| 1121 | } |
| 1122 | |
| 1123 | |
| 1124 | int luaH_psetstr (Table *t, TString *key, TValue *val) { |
no test coverage detected