diff options
Diffstat (limited to 'deep_test/deep_test.cpp')
-rw-r--r-- | deep_test/deep_test.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/deep_test/deep_test.cpp b/deep_test/deep_test.cpp index 3a58d81..1931e6d 100644 --- a/deep_test/deep_test.cpp +++ b/deep_test/deep_test.cpp | |||
@@ -7,18 +7,21 @@ | |||
7 | 7 | ||
8 | class MyDeepFactory : public DeepFactory | 8 | class MyDeepFactory : public DeepFactory |
9 | { | 9 | { |
10 | public: | ||
11 | |||
12 | static MyDeepFactory Instance; | ||
13 | |||
10 | private: | 14 | private: |
11 | 15 | ||
12 | DeepPrelude* newDeepObjectInternal(lua_State* L) const override; | 16 | DeepPrelude* newDeepObjectInternal(lua_State* L) const override; |
13 | void deleteDeepObjectInternal(lua_State* L, DeepPrelude* o_) const override; | 17 | void deleteDeepObjectInternal(lua_State* L, DeepPrelude* o_) const override; |
14 | void createMetatable(lua_State* L) const override | 18 | void createMetatable(lua_State* L_) const override |
15 | { | 19 | { |
16 | luaL_getmetatable(L, "deep"); | 20 | luaL_getmetatable(L_, "deep"); |
17 | } | 21 | } |
18 | char const* moduleName() const override { return "deep_test"; } | 22 | char const* moduleName() const override { return "deep_test"; } |
19 | }; | 23 | }; |
20 | 24 | /*static*/ MyDeepFactory MyDeepFactory::Instance{}; | |
21 | static MyDeepFactory g_MyDeepFactory; | ||
22 | 25 | ||
23 | // ################################################################################################# | 26 | // ################################################################################################# |
24 | 27 | ||
@@ -32,7 +35,7 @@ struct MyDeepUserdata : public DeepPrelude // Deep userdata MUST start with a De | |||
32 | 35 | ||
33 | DeepPrelude* MyDeepFactory::newDeepObjectInternal(lua_State* L) const | 36 | DeepPrelude* MyDeepFactory::newDeepObjectInternal(lua_State* L) const |
34 | { | 37 | { |
35 | MyDeepUserdata* deep_test = new MyDeepUserdata{ g_MyDeepFactory }; | 38 | MyDeepUserdata* deep_test = new MyDeepUserdata{ MyDeepFactory::Instance }; |
36 | return deep_test; | 39 | return deep_test; |
37 | } | 40 | } |
38 | 41 | ||
@@ -48,7 +51,7 @@ void MyDeepFactory::deleteDeepObjectInternal(lua_State* L, DeepPrelude* o_) cons | |||
48 | 51 | ||
49 | [[nodiscard]] static int deep_set(lua_State* L) | 52 | [[nodiscard]] static int deep_set(lua_State* L) |
50 | { | 53 | { |
51 | MyDeepUserdata* const self{ static_cast<MyDeepUserdata*>(g_MyDeepFactory.toDeep(L, 1)) }; | 54 | MyDeepUserdata* const self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, 1)) }; |
52 | lua_Integer i = lua_tointeger( L, 2); | 55 | lua_Integer i = lua_tointeger( L, 2); |
53 | self->val = i; | 56 | self->val = i; |
54 | return 0; | 57 | return 0; |
@@ -58,7 +61,7 @@ void MyDeepFactory::deleteDeepObjectInternal(lua_State* L, DeepPrelude* o_) cons | |||
58 | 61 | ||
59 | [[nodiscard]] static int deep_setuv(lua_State* L) | 62 | [[nodiscard]] static int deep_setuv(lua_State* L) |
60 | { | 63 | { |
61 | MyDeepUserdata* const self{ static_cast<MyDeepUserdata*>(g_MyDeepFactory.toDeep(L, 1)) }; | 64 | MyDeepUserdata* const self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, 1)) }; |
62 | int uv = (int) luaL_optinteger(L, 2, 1); | 65 | int uv = (int) luaL_optinteger(L, 2, 1); |
63 | lua_settop( L, 3); | 66 | lua_settop( L, 3); |
64 | lua_pushboolean( L, lua_setiuservalue( L, 1, uv) != 0); | 67 | lua_pushboolean( L, lua_setiuservalue( L, 1, uv) != 0); |
@@ -70,7 +73,7 @@ void MyDeepFactory::deleteDeepObjectInternal(lua_State* L, DeepPrelude* o_) cons | |||
70 | // won't actually do anything as deep userdata don't have uservalue slots | 73 | // won't actually do anything as deep userdata don't have uservalue slots |
71 | [[nodiscard]] static int deep_getuv(lua_State* L) | 74 | [[nodiscard]] static int deep_getuv(lua_State* L) |
72 | { | 75 | { |
73 | MyDeepUserdata* const self{ static_cast<MyDeepUserdata*>(g_MyDeepFactory.toDeep(L, 1)) }; | 76 | MyDeepUserdata* const self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, 1)) }; |
74 | int uv = (int) luaL_optinteger(L, 2, 1); | 77 | int uv = (int) luaL_optinteger(L, 2, 1); |
75 | lua_getiuservalue( L, 1, uv); | 78 | lua_getiuservalue( L, 1, uv); |
76 | return 1; | 79 | return 1; |
@@ -80,7 +83,7 @@ void MyDeepFactory::deleteDeepObjectInternal(lua_State* L, DeepPrelude* o_) cons | |||
80 | 83 | ||
81 | [[nodiscard]] static int deep_tostring(lua_State* L) | 84 | [[nodiscard]] static int deep_tostring(lua_State* L) |
82 | { | 85 | { |
83 | MyDeepUserdata* const self{ static_cast<MyDeepUserdata*>(g_MyDeepFactory.toDeep(L, 1)) }; | 86 | MyDeepUserdata* const self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, 1)) }; |
84 | lua_pushfstring(L, "%p:deep(%d)", lua_topointer(L, 1), self->val); | 87 | lua_pushfstring(L, "%p:deep(%d)", lua_topointer(L, 1), self->val); |
85 | return 1; | 88 | return 1; |
86 | } | 89 | } |
@@ -89,7 +92,7 @@ void MyDeepFactory::deleteDeepObjectInternal(lua_State* L, DeepPrelude* o_) cons | |||
89 | 92 | ||
90 | [[nodiscard]] static int deep_gc(lua_State* L) | 93 | [[nodiscard]] static int deep_gc(lua_State* L) |
91 | { | 94 | { |
92 | MyDeepUserdata* const self{ static_cast<MyDeepUserdata*>(g_MyDeepFactory.toDeep(L, 1)) }; | 95 | MyDeepUserdata* const self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, 1)) }; |
93 | return 0; | 96 | return 0; |
94 | } | 97 | } |
95 | 98 | ||
@@ -111,7 +114,7 @@ int luaD_new_deep( lua_State* L) | |||
111 | { | 114 | { |
112 | int const nuv{ static_cast<int>(luaL_optinteger(L, 1, 0)) }; | 115 | int const nuv{ static_cast<int>(luaL_optinteger(L, 1, 0)) }; |
113 | lua_settop(L, 0); | 116 | lua_settop(L, 0); |
114 | return g_MyDeepFactory.pushDeepUserdata(Dest{ L }, nuv); | 117 | return MyDeepFactory::Instance.pushDeepUserdata(DestState{ L }, nuv); |
115 | } | 118 | } |
116 | 119 | ||
117 | // ################################################################################################# | 120 | // ################################################################################################# |