diff options
Diffstat (limited to 'src/uniquekey.h')
-rw-r--r-- | src/uniquekey.h | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/src/uniquekey.h b/src/uniquekey.h index 93aaf37..bd3b61f 100644 --- a/src/uniquekey.h +++ b/src/uniquekey.h | |||
@@ -31,7 +31,7 @@ class UniqueKey | |||
31 | return m_storage == rhs_.m_storage; | 31 | return m_storage == rhs_.m_storage; |
32 | } | 32 | } |
33 | 33 | ||
34 | void push(lua_State* const L) const | 34 | void pushKey(lua_State* const L) const |
35 | { | 35 | { |
36 | lua_pushlightuserdata(L, std::bit_cast<void*>(m_storage)); | 36 | lua_pushlightuserdata(L, std::bit_cast<void*>(m_storage)); |
37 | } | 37 | } |
@@ -39,17 +39,38 @@ class UniqueKey | |||
39 | { | 39 | { |
40 | return lua_touserdata(L, i) == std::bit_cast<void*>(m_storage); | 40 | return lua_touserdata(L, i) == std::bit_cast<void*>(m_storage); |
41 | } | 41 | } |
42 | void query_registry(lua_State* const L) const | 42 | void pushValue(lua_State* const L) const |
43 | { | 43 | { |
44 | push(L); | 44 | pushKey(L); |
45 | lua_rawget(L, LUA_REGISTRYINDEX); | 45 | lua_rawget(L, LUA_REGISTRYINDEX); |
46 | } | 46 | } |
47 | template <typename OP> | 47 | template <typename OP> |
48 | void set_registry(lua_State* L, OP operation_) const | 48 | void setValue(lua_State* L, OP operation_) const |
49 | { | 49 | { |
50 | // Note we can't check stack consistency because operation is not always a push (could be insert, replace, whatever) | 50 | // Note we can't check stack consistency because operation is not always a push (could be insert, replace, whatever) |
51 | push(L); // ... key | 51 | pushKey(L); // ... key |
52 | operation_(L); // ... key value | 52 | operation_(L); // ... key value |
53 | lua_rawset(L, LUA_REGISTRYINDEX); // ... | 53 | lua_rawset(L, LUA_REGISTRYINDEX); // ... |
54 | } | 54 | } |
55 | template <typename T> | ||
56 | T* readLightUserDataValue(lua_State* const L) const | ||
57 | { | ||
58 | STACK_GROW(L, 1); | ||
59 | STACK_CHECK_START_REL(L, 0); | ||
60 | pushValue(L); | ||
61 | T* const value{ lua_tolightuserdata<T>(L, -1) }; // lightuserdata/nil | ||
62 | lua_pop(L, 1); | ||
63 | STACK_CHECK(L, 0); | ||
64 | return value; | ||
65 | } | ||
66 | bool readBoolValue(lua_State* const L) const | ||
67 | { | ||
68 | STACK_GROW(L, 1); | ||
69 | STACK_CHECK_START_REL(L, 0); | ||
70 | pushValue(L); | ||
71 | bool const value{ lua_toboolean(L, -1) ? true : false}; // bool/nil | ||
72 | lua_pop(L, 1); | ||
73 | STACK_CHECK(L, 0); | ||
74 | return value; | ||
75 | } | ||
55 | }; | 76 | }; |