diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-10-28 17:24:30 +0100 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-10-28 17:24:30 +0100 |
commit | c1859c3bab84dd1e712b946f4976702cfd9db5d2 (patch) | |
tree | 760bc5caf416e27eeea66e7a9e517db092286e3a /src/deep.h | |
parent | 0c23f179a46f919adf075b46f4cb8cbff3fc8ebb (diff) | |
download | lanes-c1859c3bab84dd1e712b946f4976702cfd9db5d2.tar.gz lanes-c1859c3bab84dd1e712b946f4976702cfd9db5d2.tar.bz2 lanes-c1859c3bab84dd1e712b946f4976702cfd9db5d2.zip |
Renamed _pch.h → _pch.hpp, deep.h → deep.hpp, lanes.h → lanes.hpp
Diffstat (limited to 'src/deep.h')
-rw-r--r-- | src/deep.h | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/src/deep.h b/src/deep.h deleted file mode 100644 index 0ea2712..0000000 --- a/src/deep.h +++ /dev/null | |||
@@ -1,76 +0,0 @@ | |||
1 | #pragma once | ||
2 | |||
3 | /* | ||
4 | * public 'deep' API to be used by external modules if they want to implement Lanes-aware userdata | ||
5 | * said modules can either link against lanes, or embed compat.cpp/h deep.cpp/h tools.cpp/h universe.cpp/h | ||
6 | */ | ||
7 | |||
8 | #include "lanesconf.h" | ||
9 | #include "uniquekey.h" | ||
10 | |||
11 | // forwards | ||
12 | enum class LookupMode; | ||
13 | class DeepFactory; | ||
14 | class Universe; | ||
15 | |||
16 | // ################################################################################################# | ||
17 | |||
18 | // xxh64 of string "kDeepVersion_1" generated at https://www.pelock.com/products/hash-calculator | ||
19 | static constexpr UniqueKey kDeepVersion{ 0x91171AEC6641E9DBull, "kDeepVersion" }; | ||
20 | |||
21 | // should be used as header for deep userdata | ||
22 | // a deep userdata is a full userdata that stores a single pointer to the actual DeepPrelude-derived object | ||
23 | struct DeepPrelude | ||
24 | { | ||
25 | UniqueKey const magic{ kDeepVersion }; | ||
26 | // when stored in a keeper state, the full userdata doesn't have a metatable, so we need direct access to the factory | ||
27 | DeepFactory& factory; | ||
28 | // data is destroyed when refcount is 0 | ||
29 | std::atomic<int> refcount{ 0 }; | ||
30 | |||
31 | DeepPrelude(DeepFactory& factory_) | ||
32 | : factory{ factory_ } | ||
33 | { | ||
34 | } | ||
35 | |||
36 | void push(lua_State* L_) const; | ||
37 | }; | ||
38 | |||
39 | // ################################################################################################# | ||
40 | |||
41 | // external C modules should create a single object implementing that interface for each Deep userdata class they want to expose | ||
42 | class DeepFactory | ||
43 | { | ||
44 | protected: | ||
45 | // protected non-virtual destructor: Lanes won't manage the Factory's lifetime | ||
46 | DeepFactory() = default; | ||
47 | virtual ~DeepFactory() = default; | ||
48 | |||
49 | public: | ||
50 | // non-copyable, non-movable | ||
51 | DeepFactory(DeepFactory const&) = delete; | ||
52 | DeepFactory(DeepFactory const&&) = delete; | ||
53 | DeepFactory& operator=(DeepFactory const&) = delete; | ||
54 | DeepFactory& operator=(DeepFactory const&&) = delete; | ||
55 | |||
56 | private: | ||
57 | // NVI: private overrides | ||
58 | virtual void createMetatable(lua_State* L_) const = 0; | ||
59 | virtual void deleteDeepObjectInternal(lua_State* L_, DeepPrelude* o_) const = 0; | ||
60 | [[nodiscard]] virtual DeepPrelude* newDeepObjectInternal(lua_State* L_) const = 0; | ||
61 | [[nodiscard]] virtual std::string_view moduleName() const = 0; | ||
62 | |||
63 | private: | ||
64 | void storeDeepLookup(lua_State* L_) const; | ||
65 | |||
66 | public: | ||
67 | // NVI: public interface | ||
68 | static void DeleteDeepObject(lua_State* L_, DeepPrelude* o_); | ||
69 | [[nodiscard]] static bool IsDeepUserdata(lua_State* const L_, StackIndex const idx_); | ||
70 | [[nodiscard]] static DeepFactory* LookupFactory(lua_State* L_, StackIndex index_, LookupMode mode_); | ||
71 | static void PushDeepProxy(DestState L_, DeepPrelude* o_, UserValueCount nuv_, LookupMode mode_, lua_State* errL_); | ||
72 | void pushDeepUserdata(DestState L_, UserValueCount nuv_) const; | ||
73 | [[nodiscard]] DeepPrelude* toDeep(lua_State* L_, StackIndex index_) const; | ||
74 | }; | ||
75 | |||
76 | // ################################################################################################# | ||