aboutsummaryrefslogtreecommitdiff
path: root/src/deep.h
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-03-27 10:37:05 +0100
committerBenoit Germain <benoit.germain@ubisoft.com>2024-03-27 10:37:05 +0100
commit9e3ca50cfafa0d7dc3e15f3b6a635aef6a938b80 (patch)
tree0b8dcb8cf1d90fedca7234e8a0179a09514a12bc /src/deep.h
parentf214d35df5f09e7026dafd8553e83cc6ea21cbde (diff)
downloadlanes-9e3ca50cfafa0d7dc3e15f3b6a635aef6a938b80.tar.gz
lanes-9e3ca50cfafa0d7dc3e15f3b6a635aef6a938b80.tar.bz2
lanes-9e3ca50cfafa0d7dc3e15f3b6a635aef6a938b80.zip
C++ migration: new helper templates lua_tolightuserdata and lua_tofulluserdata
Diffstat (limited to 'src/deep.h')
-rw-r--r--src/deep.h11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/deep.h b/src/deep.h
index 878fa63..2983427 100644
--- a/src/deep.h
+++ b/src/deep.h
@@ -36,19 +36,20 @@ enum DeepOp
36 eDO_module, 36 eDO_module,
37}; 37};
38 38
39using luaG_IdFunction = void*( lua_State* L, DeepOp op_); 39using luaG_IdFunction = void*(*)( lua_State* L, DeepOp op_);
40 40
41// ################################################################################################ 41// ################################################################################################
42 42
43// xxh64 of string "DEEP_VERSION_3" generated at https://www.pelock.com/products/hash-calculator 43// xxh64 of string "DEEP_VERSION_3" generated at https://www.pelock.com/products/hash-calculator
44static constexpr UniqueKey DEEP_VERSION{ 0xB2CC0FD9C0AE9674ull }; 44static constexpr UniqueKey DEEP_VERSION{ 0xB2CC0FD9C0AE9674ull };
45 45
46// should be used as header for full userdata 46// should be used as header for deep userdata
47// a deep userdata is a full userdata that stores a single pointer to the actual DeepPrelude-derived object
47struct DeepPrelude 48struct DeepPrelude
48{ 49{
49 UniqueKey const magic{ DEEP_VERSION }; 50 UniqueKey const magic{ DEEP_VERSION };
50 // when stored in a keeper state, the full userdata doesn't have a metatable, so we need direct access to the idfunc 51 // when stored in a keeper state, the full userdata doesn't have a metatable, so we need direct access to the idfunc
51 luaG_IdFunction* idfunc { nullptr }; 52 luaG_IdFunction idfunc { nullptr };
52 // data is destroyed when refcount is 0 53 // data is destroyed when refcount is 0
53 std::atomic<int> m_refcount{ 0 }; 54 std::atomic<int> m_refcount{ 0 };
54}; 55};
@@ -56,5 +57,5 @@ struct DeepPrelude
56char const* push_deep_proxy(lua_State* L, DeepPrelude* prelude, int nuv_, LookupMode mode_); 57char const* push_deep_proxy(lua_State* L, DeepPrelude* prelude, int nuv_, LookupMode mode_);
57void free_deep_prelude( lua_State* L, DeepPrelude* prelude_); 58void free_deep_prelude( lua_State* L, DeepPrelude* prelude_);
58 59
59LANES_API int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction* idfunc, int nuv_); 60LANES_API int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction idfunc, int nuv_);
60LANES_API void* luaG_todeep( lua_State* L, luaG_IdFunction* idfunc, int index); 61LANES_API DeepPrelude* luaG_todeep(lua_State* L, luaG_IdFunction idfunc, int index);