| 202 | } |
| 203 | |
| 204 | void PushHash(lua_State* L, dmhash_t hash) |
| 205 | { |
| 206 | int top = lua_gettop(L); |
| 207 | |
| 208 | HContext context = dmScript::GetScriptContext(L); |
| 209 | |
| 210 | dmHashTable64<int>* instances = &context->m_HashInstances; |
| 211 | int* refp = instances->Get(hash); |
| 212 | |
| 213 | if (refp) |
| 214 | { |
| 215 | lua_rawgeti(L, LUA_REGISTRYINDEX, context->m_ContextWeakTableRef); |
| 216 | // [-1] weak_table |
| 217 | PushHashWeakTableKey(L, hash); |
| 218 | // [-2] weak_table |
| 219 | // [-1] key |
| 220 | lua_rawget(L, -2); |
| 221 | // [-2] weak_table |
| 222 | // [-1] value or nil |
| 223 | if (lua_isnil(L, -1)) |
| 224 | { |
| 225 | lua_pop(L, 1); // remove nil |
| 226 | //[-1] weak_table |
| 227 | |
| 228 | // Create new userdata and re-register it |
| 229 | lua_pop(L, 1); // remove weak_table |
| 230 | CreateLuaHashUserdata(L, hash); |
| 231 | } |
| 232 | else |
| 233 | { |
| 234 | lua_remove(L, -2); // remove weak_table |
| 235 | // [-1] hash |
| 236 | } |
| 237 | } |
| 238 | else |
| 239 | { |
| 240 | CreateLuaHashUserdata(L, hash); |
| 241 | } |
| 242 | |
| 243 | assert(top + 1 == lua_gettop(L)); |
| 244 | } |
| 245 | |
| 246 | void ReleaseHash(lua_State* L, dmhash_t hash) |
| 247 | { |