diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-12-10 17:08:15 +0100 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-12-10 17:08:15 +0100 |
commit | 04f59310579a97102461710f6b3c8826e72723b3 (patch) | |
tree | d241690d2fd9041ec0e086a16e78228b501ececa | |
parent | 18c708eb8fbe995efe4b06b93421db3d25e22636 (diff) | |
download | lanes-04f59310579a97102461710f6b3c8826e72723b3.tar.gz lanes-04f59310579a97102461710f6b3c8826e72723b3.tar.bz2 lanes-04f59310579a97102461710f6b3c8826e72723b3.zip |
Expanded deep_test a bit
-rw-r--r-- | deep_test/deep_test.cpp | 51 | ||||
-rw-r--r-- | src/deep.cpp | 2 | ||||
-rw-r--r-- | src/deep.hpp | 2 |
3 files changed, 48 insertions, 7 deletions
diff --git a/deep_test/deep_test.cpp b/deep_test/deep_test.cpp index 451e0f1..17c398a 100644 --- a/deep_test/deep_test.cpp +++ b/deep_test/deep_test.cpp | |||
@@ -52,16 +52,29 @@ void MyDeepFactory::deleteDeepObjectInternal(lua_State* const L_, DeepPrelude* c | |||
52 | // ################################################################################################# | 52 | // ################################################################################################# |
53 | 53 | ||
54 | [[nodiscard]] | 54 | [[nodiscard]] |
55 | static int deep_gc(lua_State* L) | 55 | static int deep_gc(lua_State* const L_) |
56 | { | 56 | { |
57 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, StackIndex{ 1 })) }; | 57 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L_, StackIndex{ 1 })) }; |
58 | luaL_argcheck(L, 1, !_self->inUse.load(), "being collected while in use!"); | 58 | luaL_argcheck(L_, 1, !_self->inUse.load(), "being collected while in use!"); |
59 | if (lua_getiuservalue(L_, -1, 1) == LUA_TFUNCTION) { | ||
60 | lua_call(L_, 0, 0); | ||
61 | } | ||
59 | return 0; | 62 | return 0; |
60 | } | 63 | } |
61 | 64 | ||
62 | // ################################################################################################# | 65 | // ################################################################################################# |
63 | 66 | ||
64 | [[nodiscard]] | 67 | [[nodiscard]] |
68 | static int deep_get(lua_State* const L_) | ||
69 | { | ||
70 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L_, StackIndex{ 1 })) }; | ||
71 | lua_pushinteger(L_, _self->val); | ||
72 | return 1; | ||
73 | } | ||
74 | |||
75 | // ################################################################################################# | ||
76 | |||
77 | [[nodiscard]] | ||
65 | static int deep_tostring(lua_State* L) | 78 | static int deep_tostring(lua_State* L) |
66 | { | 79 | { |
67 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, StackIndex{ 1 })) }; | 80 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, StackIndex{ 1 })) }; |
@@ -101,6 +114,16 @@ static int deep_invoke(lua_State* L) | |||
101 | // ################################################################################################# | 114 | // ################################################################################################# |
102 | 115 | ||
103 | [[nodiscard]] | 116 | [[nodiscard]] |
117 | static int deep_refcount(lua_State* const L_) | ||
118 | { | ||
119 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L_, StackIndex{ 1 })) }; | ||
120 | lua_pushinteger(L_, _self->getRefcount()); | ||
121 | return 1; | ||
122 | } | ||
123 | |||
124 | // ################################################################################################# | ||
125 | |||
126 | [[nodiscard]] | ||
104 | static int deep_set(lua_State* const L_) | 127 | static int deep_set(lua_State* const L_) |
105 | { | 128 | { |
106 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L_, StackIndex{ 1 })) }; | 129 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L_, StackIndex{ 1 })) }; |
@@ -130,8 +153,10 @@ static int deep_setuv(lua_State* L) | |||
130 | static luaL_Reg const deep_mt[] = { | 153 | static luaL_Reg const deep_mt[] = { |
131 | { "__gc", deep_gc }, | 154 | { "__gc", deep_gc }, |
132 | { "__tostring", deep_tostring }, | 155 | { "__tostring", deep_tostring }, |
156 | { "get", deep_get }, | ||
133 | { "getuv", deep_getuv }, | 157 | { "getuv", deep_getuv }, |
134 | { "invoke", deep_invoke }, | 158 | { "invoke", deep_invoke }, |
159 | { "refcount", deep_refcount }, | ||
135 | { "set", deep_set }, | 160 | { "set", deep_set }, |
136 | { "setuv", deep_setuv }, | 161 | { "setuv", deep_setuv }, |
137 | { nullptr, nullptr } | 162 | { nullptr, nullptr } |
@@ -158,6 +183,16 @@ struct MyClonableUserdata | |||
158 | // ################################################################################################# | 183 | // ################################################################################################# |
159 | 184 | ||
160 | [[nodiscard]] | 185 | [[nodiscard]] |
186 | static int clonable_get(lua_State* const L_) | ||
187 | { | ||
188 | MyClonableUserdata* const _self{ static_cast<MyClonableUserdata*>(lua_touserdata(L_, 1)) }; | ||
189 | lua_pushinteger(L_, _self->val); | ||
190 | return 1; | ||
191 | } | ||
192 | |||
193 | // ################################################################################################# | ||
194 | |||
195 | [[nodiscard]] | ||
161 | static int clonable_set(lua_State* L) | 196 | static int clonable_set(lua_State* L) |
162 | { | 197 | { |
163 | MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)); | 198 | MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)); |
@@ -202,9 +237,12 @@ static int clonable_tostring(lua_State* L) | |||
202 | // ################################################################################################# | 237 | // ################################################################################################# |
203 | 238 | ||
204 | [[nodiscard]] | 239 | [[nodiscard]] |
205 | static int clonable_gc(lua_State* L) | 240 | static int clonable_gc(lua_State* const L_) |
206 | { | 241 | { |
207 | MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)); | 242 | MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L_, 1)); |
243 | if (lua_getiuservalue(L_, -1, 1) == LUA_TFUNCTION) { | ||
244 | lua_call(L_, 0, 0); | ||
245 | } | ||
208 | return 0; | 246 | return 0; |
209 | } | 247 | } |
210 | 248 | ||
@@ -234,9 +272,10 @@ static int clonable_lanesclone(lua_State* L) | |||
234 | // ################################################################################################# | 272 | // ################################################################################################# |
235 | 273 | ||
236 | static luaL_Reg const clonable_mt[] = { | 274 | static luaL_Reg const clonable_mt[] = { |
237 | { "__tostring", clonable_tostring }, | ||
238 | { "__gc", clonable_gc }, | 275 | { "__gc", clonable_gc }, |
239 | { "__lanesclone", clonable_lanesclone }, | 276 | { "__lanesclone", clonable_lanesclone }, |
277 | { "__tostring", clonable_tostring }, | ||
278 | { "get", clonable_get }, | ||
240 | { "set", clonable_set }, | 279 | { "set", clonable_set }, |
241 | { "setuv", clonable_setuv }, | 280 | { "setuv", clonable_setuv }, |
242 | { "getuv", clonable_getuv }, | 281 | { "getuv", clonable_getuv }, |
diff --git a/src/deep.cpp b/src/deep.cpp index 7b287f5..bd340f4 100644 --- a/src/deep.cpp +++ b/src/deep.cpp | |||
@@ -116,7 +116,7 @@ int DeepFactory::DeepGC(lua_State* const L_) | |||
116 | // need an empty stack in case we are GC_ing from a Keeper, so that empty stack checks aren't triggered | 116 | // need an empty stack in case we are GC_ing from a Keeper, so that empty stack checks aren't triggered |
117 | lua_pop(L_, 2); // L_: | 117 | lua_pop(L_, 2); // L_: |
118 | } | 118 | } |
119 | DeepFactory::DeleteDeepObject(L_, _p); | 119 | DeleteDeepObject(L_, _p); |
120 | } | 120 | } |
121 | return 0; | 121 | return 0; |
122 | } | 122 | } |
diff --git a/src/deep.hpp b/src/deep.hpp index e4bdaca..6bc3b20 100644 --- a/src/deep.hpp +++ b/src/deep.hpp | |||
@@ -41,6 +41,8 @@ class DeepPrelude | |||
41 | 41 | ||
42 | public: | 42 | public: |
43 | void push(lua_State* L_) const; | 43 | void push(lua_State* L_) const; |
44 | [[nodiscard]] | ||
45 | int getRefcount() const { return refcount.load(std::memory_order_relaxed); } | ||
44 | }; | 46 | }; |
45 | 47 | ||
46 | // ################################################################################################# | 48 | // ################################################################################################# |