diff options
Diffstat (limited to 'src/keeper.c')
-rw-r--r-- | src/keeper.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/keeper.c b/src/keeper.c index 907334f..715583b 100644 --- a/src/keeper.c +++ b/src/keeper.c | |||
@@ -48,6 +48,7 @@ | |||
48 | #include "compat.h" | 48 | #include "compat.h" |
49 | #include "tools.h" | 49 | #include "tools.h" |
50 | #include "universe.h" | 50 | #include "universe.h" |
51 | #include "uniquekey.h" | ||
51 | 52 | ||
52 | //################################################################################### | 53 | //################################################################################### |
53 | // Keeper implementation | 54 | // Keeper implementation |
@@ -160,13 +161,14 @@ static void fifo_pop( lua_State* L, keeper_fifo* fifo_, lua_Integer count_) | |||
160 | 161 | ||
161 | // in: linda_ud expected at *absolute* stack slot idx | 162 | // in: linda_ud expected at *absolute* stack slot idx |
162 | // out: fifos[ud] | 163 | // out: fifos[ud] |
163 | static void* const fifos_key = (void*) prepare_fifo_access; | 164 | // crc64/we of string "FIFOS_KEY" generated at http://www.nitrxgen.net/hashgen/ |
165 | static DECLARE_CONST_UNIQUE_KEY( FIFOS_KEY, 0xdce50bbc351cd465); | ||
164 | static void push_table( lua_State* L, int idx_) | 166 | static void push_table( lua_State* L, int idx_) |
165 | { | 167 | { |
166 | STACK_GROW( L, 4); | 168 | STACK_GROW( L, 4); |
167 | STACK_CHECK( L); | 169 | STACK_CHECK( L); |
168 | idx_ = lua_absindex( L, idx_); | 170 | idx_ = lua_absindex( L, idx_); |
169 | lua_pushlightuserdata( L, fifos_key); // ud fifos_key | 171 | push_unique_key( L, FIFOS_KEY); // ud fifos_key |
170 | lua_rawget( L, LUA_REGISTRYINDEX); // ud fifos | 172 | lua_rawget( L, LUA_REGISTRYINDEX); // ud fifos |
171 | lua_pushvalue( L, idx_); // ud fifos ud | 173 | lua_pushvalue( L, idx_); // ud fifos ud |
172 | lua_rawget( L, -2); // ud fifos fifos[ud] | 174 | lua_rawget( L, -2); // ud fifos fifos[ud] |
@@ -191,7 +193,7 @@ int keeper_push_linda_storage( Universe* U, lua_State* L, void* ptr_, ptrdiff_t | |||
191 | if( KL == NULL) return 0; | 193 | if( KL == NULL) return 0; |
192 | STACK_GROW( KL, 4); | 194 | STACK_GROW( KL, 4); |
193 | STACK_CHECK( KL); | 195 | STACK_CHECK( KL); |
194 | lua_pushlightuserdata( KL, fifos_key); // fifos_key | 196 | push_unique_key( KL, FIFOS_KEY); // fifos_key |
195 | lua_rawget( KL, LUA_REGISTRYINDEX); // fifos | 197 | lua_rawget( KL, LUA_REGISTRYINDEX); // fifos |
196 | lua_pushlightuserdata( KL, ptr_); // fifos ud | 198 | lua_pushlightuserdata( KL, ptr_); // fifos ud |
197 | lua_rawget( KL, -2); // fifos storage | 199 | lua_rawget( KL, -2); // fifos storage |
@@ -239,7 +241,7 @@ int keeper_push_linda_storage( Universe* U, lua_State* L, void* ptr_, ptrdiff_t | |||
239 | int keepercall_clear( lua_State* L) | 241 | int keepercall_clear( lua_State* L) |
240 | { | 242 | { |
241 | STACK_GROW( L, 3); | 243 | STACK_GROW( L, 3); |
242 | lua_pushlightuserdata( L, fifos_key); // ud fifos_key | 244 | push_unique_key( L, FIFOS_KEY); // ud fifos_key |
243 | lua_rawget( L, LUA_REGISTRYINDEX); // ud fifos | 245 | lua_rawget( L, LUA_REGISTRYINDEX); // ud fifos |
244 | lua_pushvalue( L, 1); // ud fifos ud | 246 | lua_pushvalue( L, 1); // ud fifos ud |
245 | lua_pushnil( L); // ud fifos ud nil | 247 | lua_pushnil( L); // ud fifos ud nil |
@@ -704,7 +706,7 @@ void init_keepers( Universe* U, lua_State* L) | |||
704 | lua_setglobal( K, "decoda_name"); // | 706 | lua_setglobal( K, "decoda_name"); // |
705 | 707 | ||
706 | // create the fifos table in the keeper state | 708 | // create the fifos table in the keeper state |
707 | lua_pushlightuserdata( K, fifos_key); // fifo_key | 709 | push_unique_key( K, FIFOS_KEY); // fifo_key |
708 | lua_newtable( K); // fifo_key {} | 710 | lua_newtable( K); // fifo_key {} |
709 | lua_rawset( K, LUA_REGISTRYINDEX); // | 711 | lua_rawset( K, LUA_REGISTRYINDEX); // |
710 | 712 | ||
@@ -754,13 +756,13 @@ void keeper_toggle_nil_sentinels( lua_State* L, int val_i_, LookupMode mode_) | |||
754 | { | 756 | { |
755 | if( lua_isnil( L, i)) | 757 | if( lua_isnil( L, i)) |
756 | { | 758 | { |
757 | lua_pushlightuserdata( L, NIL_SENTINEL); | 759 | push_unique_key( L, NIL_SENTINEL); |
758 | lua_replace( L, i); | 760 | lua_replace( L, i); |
759 | } | 761 | } |
760 | } | 762 | } |
761 | else | 763 | else |
762 | { | 764 | { |
763 | if( lua_touserdata( L, i) == NIL_SENTINEL) | 765 | if( equal_unique_key( L, i, NIL_SENTINEL)) |
764 | { | 766 | { |
765 | lua_pushnil( L); | 767 | lua_pushnil( L); |
766 | lua_replace( L, i); | 768 | lua_replace( L, i); |