| 89 | struct weak_ref::impl |
| 90 | { |
| 91 | impl(lua_State* s, int index) |
| 92 | : count(0) |
| 93 | , state(s) |
| 94 | , ref(0) |
| 95 | { |
| 96 | lua_pushvalue(s, index); |
| 97 | get_weak_table(s); |
| 98 | |
| 99 | lua_rawgeti(s, -1, freelist_ref); |
| 100 | ref = (int)lua_tonumber(s, -1); |
| 101 | lua_pop(s, 1); |
| 102 | |
| 103 | if (ref == 0) |
| 104 | { |
| 105 | lua_rawgeti(s, -1, count_ref); |
| 106 | ref = (int)lua_tonumber(s, -1) + 1; |
| 107 | lua_pop(s, 1); |
| 108 | lua_pushnumber(s, (lua_Number)ref); |
| 109 | lua_rawseti(s, -2, count_ref); |
| 110 | } |
| 111 | else |
| 112 | { |
| 113 | lua_rawgeti(s, -1, ref); |
| 114 | lua_rawseti(s, -2, freelist_ref); |
| 115 | } |
| 116 | |
| 117 | lua_pushvalue(s, -2); // duplicate value |
| 118 | lua_rawseti(s, -2, ref); |
| 119 | lua_pop(s, 2); // pop weakref table and value |
| 120 | } |
| 121 | |
| 122 | ~impl() |
| 123 | { |
nothing calls this directly
no test coverage detected