diff options
Diffstat (limited to '')
-rw-r--r-- | src/universe.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/universe.cpp b/src/universe.cpp index 095f000..3792da6 100644 --- a/src/universe.cpp +++ b/src/universe.cpp | |||
@@ -36,17 +36,22 @@ THE SOFTWARE. | |||
36 | #include "macros_and_utils.h" | 36 | #include "macros_and_utils.h" |
37 | #include "uniquekey.h" | 37 | #include "uniquekey.h" |
38 | 38 | ||
39 | // crc64/we of string "UNIVERSE_REGKEY" generated at http://www.nitrxgen.net/hashgen/ | 39 | // xxh64 of string "UNIVERSE_FULL_REGKEY" generated at http://www.nitrxgen.net/hashgen/ |
40 | static constexpr UniqueKey UNIVERSE_REGKEY{ 0x9f877b2cf078f17full }; | 40 | static constexpr UniqueKey UNIVERSE_FULL_REGKEY{ 0x99CA130C09EDC074ull }; |
41 | // xxh64 of string "UNIVERSE_LIGHT_REGKEY" generated at http://www.nitrxgen.net/hashgen/ | ||
42 | static constexpr UniqueKey UNIVERSE_LIGHT_REGKEY{ 0x3663C07C742CEB81ull }; | ||
41 | 43 | ||
42 | // ################################################################################################ | 44 | // ################################################################################################ |
43 | 45 | ||
46 | // only called from the master state | ||
44 | Universe* universe_create(lua_State* L) | 47 | Universe* universe_create(lua_State* L) |
45 | { | 48 | { |
46 | Universe* const U = static_cast<Universe*>(lua_newuserdatauv(L, sizeof(Universe), 0)); // universe | 49 | ASSERT_L(universe_get(L) == nullptr); |
50 | Universe* const U = static_cast<Universe*>(lua_newuserdatauv(L, sizeof(Universe), 0)); // universe | ||
47 | U->Universe::Universe(); | 51 | U->Universe::Universe(); |
48 | STACK_CHECK_START_REL(L, 1); | 52 | STACK_CHECK_START_REL(L, 1); |
49 | UNIVERSE_REGKEY.set_registry(L, [](lua_State* L) { lua_pushvalue(L, -2); }); // universe | 53 | UNIVERSE_FULL_REGKEY.set_registry(L, [](lua_State* L) { lua_pushvalue(L, -2); }); |
54 | UNIVERSE_LIGHT_REGKEY.set_registry(L, [U](lua_State* L) { lua_pushlightuserdata( L, U); }); | ||
50 | STACK_CHECK(L, 1); | 55 | STACK_CHECK(L, 1); |
51 | return U; | 56 | return U; |
52 | } | 57 | } |
@@ -55,8 +60,9 @@ Universe* universe_create(lua_State* L) | |||
55 | 60 | ||
56 | void universe_store(lua_State* L, Universe* U) | 61 | void universe_store(lua_State* L, Universe* U) |
57 | { | 62 | { |
63 | ASSERT_L(universe_get(L) == nullptr); | ||
58 | STACK_CHECK_START_REL(L, 0); | 64 | STACK_CHECK_START_REL(L, 0); |
59 | UNIVERSE_REGKEY.set_registry(L, [U](lua_State* L) { U ? lua_pushlightuserdata( L, U) : lua_pushnil( L); }); | 65 | UNIVERSE_LIGHT_REGKEY.set_registry(L, [U](lua_State* L) { U ? lua_pushlightuserdata( L, U) : lua_pushnil( L); }); |
60 | STACK_CHECK( L, 0); | 66 | STACK_CHECK( L, 0); |
61 | } | 67 | } |
62 | 68 | ||
@@ -66,8 +72,8 @@ Universe* universe_get(lua_State* L) | |||
66 | { | 72 | { |
67 | STACK_GROW(L, 2); | 73 | STACK_GROW(L, 2); |
68 | STACK_CHECK_START_REL(L, 0); | 74 | STACK_CHECK_START_REL(L, 0); |
69 | UNIVERSE_REGKEY.query_registry(L); | 75 | UNIVERSE_LIGHT_REGKEY.query_registry(L); |
70 | Universe* const universe{ lua_touserdata<Universe>(L, -1) }; // nullptr if nil | 76 | Universe* const universe{ lua_tolightuserdata<Universe>(L, -1) }; // nullptr if nil |
71 | lua_pop(L, 1); | 77 | lua_pop(L, 1); |
72 | STACK_CHECK(L, 0); | 78 | STACK_CHECK(L, 0); |
73 | return universe; | 79 | return universe; |