diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-24 18:03:06 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-24 18:03:06 +0200 |
commit | 5e3f33bd66ef5b21568fde7866ca4ba9a7496180 (patch) | |
tree | d2692b78cb20655de5ebf842de72fd2b806d12db /src | |
parent | 0a481b9aef3726763c572ad3ce6d44ea14dd35ba (diff) | |
download | lanes-5e3f33bd66ef5b21568fde7866ca4ba9a7496180.tar.gz lanes-5e3f33bd66ef5b21568fde7866ca4ba9a7496180.tar.bz2 lanes-5e3f33bd66ef5b21568fde7866ca4ba9a7496180.zip |
Lindas now accept deep user data as valid keys
Diffstat (limited to 'src')
-rw-r--r-- | src/deep.cpp | 9 | ||||
-rw-r--r-- | src/deep.h | 1 | ||||
-rw-r--r-- | src/linda.cpp | 8 |
3 files changed, 17 insertions, 1 deletions
diff --git a/src/deep.cpp b/src/deep.cpp index 8754178..bac011f 100644 --- a/src/deep.cpp +++ b/src/deep.cpp | |||
@@ -130,8 +130,15 @@ void DeepFactory::DeleteDeepObject(lua_State* const L_, DeepPrelude* const o_) | |||
130 | 130 | ||
131 | // ################################################################################################# | 131 | // ################################################################################################# |
132 | 132 | ||
133 | bool DeepFactory::IsDeepUserdata(lua_State* const L_, int const idx_) | ||
134 | { | ||
135 | return LookupFactory(L_, idx_, LookupMode::LaneBody) != nullptr; | ||
136 | } | ||
137 | |||
138 | // ################################################################################################# | ||
139 | |||
133 | // Return the registered factory for 'index' (deep userdata proxy), or nullptr if 'index' is not a deep userdata proxy. | 140 | // Return the registered factory for 'index' (deep userdata proxy), or nullptr if 'index' is not a deep userdata proxy. |
134 | [[nodiscard]] DeepFactory* DeepFactory::LookupFactory(lua_State* const L_, int const index_, LookupMode const mode_) | 141 | DeepFactory* DeepFactory::LookupFactory(lua_State* const L_, int const index_, LookupMode const mode_) |
135 | { | 142 | { |
136 | // when looking inside a keeper, we are 100% sure the object is a deep userdata | 143 | // when looking inside a keeper, we are 100% sure the object is a deep userdata |
137 | if (mode_ == LookupMode::FromKeeper) { | 144 | if (mode_ == LookupMode::FromKeeper) { |
@@ -66,6 +66,7 @@ class DeepFactory | |||
66 | public: | 66 | public: |
67 | // NVI: public interface | 67 | // NVI: public interface |
68 | static void DeleteDeepObject(lua_State* L_, DeepPrelude* o_); | 68 | static void DeleteDeepObject(lua_State* L_, DeepPrelude* o_); |
69 | [[nodiscard]] static bool IsDeepUserdata(lua_State* const L_, int const idx_); | ||
69 | [[nodiscard]] static DeepFactory* LookupFactory(lua_State* L_, int index_, LookupMode mode_); | 70 | [[nodiscard]] static DeepFactory* LookupFactory(lua_State* L_, int index_, LookupMode mode_); |
70 | static void PushDeepProxy(DestState L_, DeepPrelude* o_, int nuv_, LookupMode mode_, lua_State* errL_); | 71 | static void PushDeepProxy(DestState L_, DeepPrelude* o_, int nuv_, LookupMode mode_, lua_State* errL_); |
71 | void pushDeepUserdata(DestState L_, int nuv_) const; | 72 | void pushDeepUserdata(DestState L_, int nuv_) const; |
diff --git a/src/linda.cpp b/src/linda.cpp index 4edc029..079ab9d 100644 --- a/src/linda.cpp +++ b/src/linda.cpp | |||
@@ -46,6 +46,7 @@ namespace { | |||
46 | 46 | ||
47 | static void CheckKeyTypes(lua_State* const L_, int const start_, int const end_) | 47 | static void CheckKeyTypes(lua_State* const L_, int const start_, int const end_) |
48 | { | 48 | { |
49 | STACK_CHECK_START_REL(L_, 0); | ||
49 | for (int const _i : std::ranges::iota_view{ start_, end_ + 1 }) { | 50 | for (int const _i : std::ranges::iota_view{ start_, end_ + 1 }) { |
50 | switch (LuaType const _t{ luaG_type(L_, _i) }) { | 51 | switch (LuaType const _t{ luaG_type(L_, _i) }) { |
51 | case LuaType::BOOLEAN: | 52 | case LuaType::BOOLEAN: |
@@ -53,6 +54,12 @@ namespace { | |||
53 | case LuaType::STRING: | 54 | case LuaType::STRING: |
54 | break; | 55 | break; |
55 | 56 | ||
57 | case LuaType::USERDATA: | ||
58 | if (!DeepFactory::IsDeepUserdata(L_, _i)) { | ||
59 | raise_luaL_error(L_, "argument #%d: can't use non-deep userdata as a key", _i); | ||
60 | } | ||
61 | break; | ||
62 | |||
56 | case LuaType::LIGHTUSERDATA: | 63 | case LuaType::LIGHTUSERDATA: |
57 | { | 64 | { |
58 | static constexpr std::array<std::reference_wrapper<UniqueKey const>, 3> kKeysToCheck{ kLindaBatched, kCancelError, kNilSentinel }; | 65 | static constexpr std::array<std::reference_wrapper<UniqueKey const>, 3> kKeysToCheck{ kLindaBatched, kCancelError, kNilSentinel }; |
@@ -69,6 +76,7 @@ namespace { | |||
69 | raise_luaL_error(L_, "argument #%d: invalid key type (not a boolean, string, number or light userdata)", _i); | 76 | raise_luaL_error(L_, "argument #%d: invalid key type (not a boolean, string, number or light userdata)", _i); |
70 | } | 77 | } |
71 | } | 78 | } |
79 | STACK_CHECK(L_, 0); | ||
72 | } | 80 | } |
73 | 81 | ||
74 | // ############################################################################################# | 82 | // ############################################################################################# |