diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-03-25 09:51:56 +0100 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-03-25 09:51:56 +0100 |
| commit | f00c77d497bc2b5f4dd55f4b21c645ea729eca70 (patch) | |
| tree | 7b73dd0411303aefe1473d1fc6f8b1b527b2a864 /deep_test | |
| parent | bfb1277b3496018b7ee12eca2fb900ebbe651b49 (diff) | |
| download | lanes-f00c77d497bc2b5f4dd55f4b21c645ea729eca70.tar.gz lanes-f00c77d497bc2b5f4dd55f4b21c645ea729eca70.tar.bz2 lanes-f00c77d497bc2b5f4dd55f4b21c645ea729eca70.zip | |
C++ migration: make deep_test build and run
Diffstat (limited to 'deep_test')
| -rw-r--r-- | deep_test/deep_test.cpp (renamed from deep_test/deep_test.c) | 137 | ||||
| -rw-r--r-- | deep_test/deep_test.vcxproj | 10 | ||||
| -rw-r--r-- | deep_test/deep_test.vcxproj.filters | 14 |
3 files changed, 77 insertions, 84 deletions
diff --git a/deep_test/deep_test.c b/deep_test/deep_test.cpp index eca7479..bbae48e 100644 --- a/deep_test/deep_test.c +++ b/deep_test/deep_test.cpp | |||
| @@ -1,29 +1,59 @@ | |||
| 1 | #include "lanes/src/deep.h" | ||
| 2 | #include "lanes/src/compat.h" | ||
| 3 | |||
| 1 | #include <malloc.h> | 4 | #include <malloc.h> |
| 2 | #include <memory.h> | 5 | #include <memory.h> |
| 3 | #include <assert.h> | 6 | #include <assert.h> |
| 4 | 7 | ||
| 5 | #include "lua.h" | ||
| 6 | #include "lualib.h" | ||
| 7 | #include "lauxlib.h" | ||
| 8 | |||
| 9 | #include "lanes/src/deep.h" | ||
| 10 | #include "lanes/src/compat.h" | ||
| 11 | |||
| 12 | // ################################################################################################ | 8 | // ################################################################################################ |
| 13 | 9 | ||
| 14 | // a lanes-deep userdata. needs DeepPrelude and luaG_newdeepuserdata from Lanes code. | 10 | // a lanes-deep userdata. needs DeepPrelude and luaG_newdeepuserdata from Lanes code. |
| 15 | struct s_MyDeepUserdata | 11 | struct MyDeepUserdata |
| 16 | { | 12 | { |
| 17 | DeepPrelude prelude; // Deep userdata MUST start with this header | 13 | DeepPrelude prelude; // Deep userdata MUST start with this header |
| 18 | lua_Integer val; | 14 | lua_Integer val{ 0 }; |
| 19 | }; | 15 | }; |
| 20 | static void* deep_test_id( lua_State* L, enum eDeepOp op_); | 16 | |
| 17 | // ################################################################################################ | ||
| 18 | |||
| 19 | static void* deep_test_id( lua_State* L, DeepOp op_) | ||
| 20 | { | ||
| 21 | switch( op_) | ||
| 22 | { | ||
| 23 | case eDO_new: | ||
| 24 | { | ||
| 25 | MyDeepUserdata* deep_test = new MyDeepUserdata; | ||
| 26 | return deep_test; | ||
| 27 | } | ||
| 28 | |||
| 29 | case eDO_delete: | ||
| 30 | { | ||
| 31 | MyDeepUserdata* deep_test = static_cast<MyDeepUserdata*>(lua_touserdata( L, 1)); | ||
| 32 | delete deep_test; | ||
| 33 | return nullptr; | ||
| 34 | } | ||
| 35 | |||
| 36 | case eDO_metatable: | ||
| 37 | { | ||
| 38 | luaL_getmetatable( L, "deep"); // mt | ||
| 39 | return nullptr; | ||
| 40 | } | ||
| 41 | |||
| 42 | case eDO_module: | ||
| 43 | return (void*)"deep_test"; | ||
| 44 | |||
| 45 | default: | ||
| 46 | { | ||
| 47 | return nullptr; | ||
| 48 | } | ||
| 49 | } | ||
| 50 | } | ||
| 21 | 51 | ||
| 22 | // ################################################################################################ | 52 | // ################################################################################################ |
| 23 | 53 | ||
| 24 | static int deep_set( lua_State* L) | 54 | static int deep_set( lua_State* L) |
| 25 | { | 55 | { |
| 26 | struct s_MyDeepUserdata* self = luaG_todeep( L, deep_test_id, 1); | 56 | MyDeepUserdata* self = static_cast<MyDeepUserdata*>(luaG_todeep(L, deep_test_id, 1)); |
| 27 | lua_Integer i = lua_tointeger( L, 2); | 57 | lua_Integer i = lua_tointeger( L, 2); |
| 28 | self->val = i; | 58 | self->val = i; |
| 29 | return 0; | 59 | return 0; |
| @@ -34,8 +64,8 @@ static int deep_set( lua_State* L) | |||
| 34 | // won't actually do anything as deep userdata don't have uservalue slots | 64 | // won't actually do anything as deep userdata don't have uservalue slots |
| 35 | static int deep_setuv( lua_State* L) | 65 | static int deep_setuv( lua_State* L) |
| 36 | { | 66 | { |
| 37 | struct s_MyDeepUserdata* self = luaG_todeep( L, deep_test_id, 1); | 67 | MyDeepUserdata* self = static_cast<MyDeepUserdata*>(luaG_todeep(L, deep_test_id, 1)); |
| 38 | int uv = (int) luaL_optinteger( L, 2, 1); | 68 | int uv = (int) luaL_optinteger(L, 2, 1); |
| 39 | lua_settop( L, 3); | 69 | lua_settop( L, 3); |
| 40 | lua_pushboolean( L, lua_setiuservalue( L, 1, uv) != 0); | 70 | lua_pushboolean( L, lua_setiuservalue( L, 1, uv) != 0); |
| 41 | return 1; | 71 | return 1; |
| @@ -46,8 +76,8 @@ static int deep_setuv( lua_State* L) | |||
| 46 | // won't actually do anything as deep userdata don't have uservalue slots | 76 | // won't actually do anything as deep userdata don't have uservalue slots |
| 47 | static int deep_getuv( lua_State* L) | 77 | static int deep_getuv( lua_State* L) |
| 48 | { | 78 | { |
| 49 | struct s_MyDeepUserdata* self = luaG_todeep( L, deep_test_id, 1); | 79 | MyDeepUserdata* self = static_cast<MyDeepUserdata*>(luaG_todeep(L, deep_test_id, 1)); |
| 50 | int uv = (int) luaL_optinteger( L, 2, 1); | 80 | int uv = (int) luaL_optinteger(L, 2, 1); |
| 51 | lua_getiuservalue( L, 1, uv); | 81 | lua_getiuservalue( L, 1, uv); |
| 52 | return 1; | 82 | return 1; |
| 53 | } | 83 | } |
| @@ -56,8 +86,8 @@ static int deep_getuv( lua_State* L) | |||
| 56 | 86 | ||
| 57 | static int deep_tostring( lua_State* L) | 87 | static int deep_tostring( lua_State* L) |
| 58 | { | 88 | { |
| 59 | struct s_MyDeepUserdata* self = luaG_todeep( L, deep_test_id, 1); | 89 | MyDeepUserdata* self = static_cast<MyDeepUserdata*>(luaG_todeep(L, deep_test_id, 1)); |
| 60 | lua_pushfstring( L, "%p:deep(%d)", lua_topointer( L, 1), self->val); | 90 | lua_pushfstring(L, "%p:deep(%d)", lua_topointer(L, 1), self->val); |
| 61 | return 1; | 91 | return 1; |
| 62 | } | 92 | } |
| 63 | 93 | ||
| @@ -65,7 +95,7 @@ static int deep_tostring( lua_State* L) | |||
| 65 | 95 | ||
| 66 | static int deep_gc( lua_State* L) | 96 | static int deep_gc( lua_State* L) |
| 67 | { | 97 | { |
| 68 | struct s_MyDeepUserdata* self = luaG_todeep( L, deep_test_id, 1); | 98 | MyDeepUserdata* self = static_cast<MyDeepUserdata*>(luaG_todeep(L, deep_test_id, 1)); |
| 69 | return 0; | 99 | return 0; |
| 70 | } | 100 | } |
| 71 | 101 | ||
| @@ -78,48 +108,11 @@ static luaL_Reg const deep_mt[] = | |||
| 78 | { "set", deep_set}, | 108 | { "set", deep_set}, |
| 79 | { "setuv", deep_setuv}, | 109 | { "setuv", deep_setuv}, |
| 80 | { "getuv", deep_getuv}, | 110 | { "getuv", deep_getuv}, |
| 81 | { NULL, NULL } | 111 | { nullptr, nullptr } |
| 82 | }; | 112 | }; |
| 83 | 113 | ||
| 84 | // ################################################################################################ | 114 | // ################################################################################################ |
| 85 | 115 | ||
| 86 | static void* deep_test_id( lua_State* L, enum eDeepOp op_) | ||
| 87 | { | ||
| 88 | switch( op_) | ||
| 89 | { | ||
| 90 | case eDO_new: | ||
| 91 | { | ||
| 92 | struct s_MyDeepUserdata* deep_test = (struct s_MyDeepUserdata*) malloc( sizeof(struct s_MyDeepUserdata)); | ||
| 93 | deep_test->prelude.magic.value = DEEP_VERSION.value; | ||
| 94 | deep_test->val = 0; | ||
| 95 | return deep_test; | ||
| 96 | } | ||
| 97 | |||
| 98 | case eDO_delete: | ||
| 99 | { | ||
| 100 | struct s_MyDeepUserdata* deep_test = (struct s_MyDeepUserdata*) lua_touserdata( L, 1); | ||
| 101 | free( deep_test); | ||
| 102 | return NULL; | ||
| 103 | } | ||
| 104 | |||
| 105 | case eDO_metatable: | ||
| 106 | { | ||
| 107 | luaL_getmetatable( L, "deep"); // mt | ||
| 108 | return NULL; | ||
| 109 | } | ||
| 110 | |||
| 111 | case eDO_module: | ||
| 112 | return "deep_test"; | ||
| 113 | |||
| 114 | default: | ||
| 115 | { | ||
| 116 | return NULL; | ||
| 117 | } | ||
| 118 | } | ||
| 119 | } | ||
| 120 | |||
| 121 | // ################################################################################################ | ||
| 122 | |||
| 123 | int luaD_new_deep( lua_State* L) | 116 | int luaD_new_deep( lua_State* L) |
| 124 | { | 117 | { |
| 125 | int nuv = (int) luaL_optinteger( L, 1, 0); | 118 | int nuv = (int) luaL_optinteger( L, 1, 0); |
| @@ -131,7 +124,7 @@ int luaD_new_deep( lua_State* L) | |||
| 131 | // ################################################################################################ | 124 | // ################################################################################################ |
| 132 | // ################################################################################################ | 125 | // ################################################################################################ |
| 133 | 126 | ||
| 134 | struct s_MyClonableUserdata | 127 | struct MyClonableUserdata |
| 135 | { | 128 | { |
| 136 | lua_Integer val; | 129 | lua_Integer val; |
| 137 | }; | 130 | }; |
| @@ -140,8 +133,8 @@ struct s_MyClonableUserdata | |||
| 140 | 133 | ||
| 141 | static int clonable_set( lua_State* L) | 134 | static int clonable_set( lua_State* L) |
| 142 | { | 135 | { |
| 143 | struct s_MyClonableUserdata* self = (struct s_MyClonableUserdata*) lua_touserdata( L, 1); | 136 | MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)); |
| 144 | lua_Integer i = lua_tointeger( L, 2); | 137 | lua_Integer i = lua_tointeger(L, 2); |
| 145 | self->val = i; | 138 | self->val = i; |
| 146 | return 0; | 139 | return 0; |
| 147 | } | 140 | } |
| @@ -150,8 +143,8 @@ static int clonable_set( lua_State* L) | |||
| 150 | 143 | ||
| 151 | static int clonable_setuv( lua_State* L) | 144 | static int clonable_setuv( lua_State* L) |
| 152 | { | 145 | { |
| 153 | struct s_MyClonableUserdata* self = (struct s_MyClonableUserdata*) lua_touserdata( L, 1); | 146 | MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)); |
| 154 | int uv = (int) luaL_optinteger( L, 2, 1); | 147 | int uv = (int) luaL_optinteger(L, 2, 1); |
| 155 | lua_settop( L, 3); | 148 | lua_settop( L, 3); |
| 156 | lua_pushboolean( L, lua_setiuservalue( L, 1, uv) != 0); | 149 | lua_pushboolean( L, lua_setiuservalue( L, 1, uv) != 0); |
| 157 | return 1; | 150 | return 1; |
| @@ -161,8 +154,8 @@ static int clonable_setuv( lua_State* L) | |||
| 161 | 154 | ||
| 162 | static int clonable_getuv( lua_State* L) | 155 | static int clonable_getuv( lua_State* L) |
| 163 | { | 156 | { |
| 164 | struct s_MyClonableUserdata* self = (struct s_MyClonableUserdata*) lua_touserdata( L, 1); | 157 | MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)); |
| 165 | int uv = (int) luaL_optinteger( L, 2, 1); | 158 | int uv = (int) luaL_optinteger(L, 2, 1); |
| 166 | lua_getiuservalue( L, 1, uv); | 159 | lua_getiuservalue( L, 1, uv); |
| 167 | return 1; | 160 | return 1; |
| 168 | } | 161 | } |
| @@ -171,8 +164,8 @@ static int clonable_getuv( lua_State* L) | |||
| 171 | 164 | ||
| 172 | static int clonable_tostring(lua_State* L) | 165 | static int clonable_tostring(lua_State* L) |
| 173 | { | 166 | { |
| 174 | struct s_MyClonableUserdata* self = (struct s_MyClonableUserdata*) lua_touserdata( L, 1); | 167 | MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)); |
| 175 | lua_pushfstring( L, "%p:clonable(%d)", lua_topointer( L, 1), self->val); | 168 | lua_pushfstring(L, "%p:clonable(%d)", lua_topointer(L, 1), self->val); |
| 176 | return 1; | 169 | return 1; |
| 177 | } | 170 | } |
| 178 | 171 | ||
| @@ -180,7 +173,7 @@ static int clonable_tostring(lua_State* L) | |||
| 180 | 173 | ||
| 181 | static int clonable_gc( lua_State* L) | 174 | static int clonable_gc( lua_State* L) |
| 182 | { | 175 | { |
| 183 | struct s_MyClonableUserdata* self = (struct s_MyClonableUserdata*) lua_touserdata( L, 1); | 176 | MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)); |
| 184 | return 0; | 177 | return 0; |
| 185 | } | 178 | } |
| 186 | 179 | ||
| @@ -193,10 +186,10 @@ static int clonable_lanesclone( lua_State* L) | |||
| 193 | { | 186 | { |
| 194 | case 3: | 187 | case 3: |
| 195 | { | 188 | { |
| 196 | struct s_MyClonableUserdata* self = lua_touserdata( L, 1); | 189 | MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)); |
| 197 | struct s_MyClonableUserdata* from = lua_touserdata( L, 2); | 190 | MyClonableUserdata* from = static_cast<MyClonableUserdata*>(lua_touserdata(L, 2)); |
| 198 | size_t len = lua_tointeger( L, 3); | 191 | size_t len = lua_tointeger( L, 3); |
| 199 | assert( len == sizeof(struct s_MyClonableUserdata)); | 192 | assert( len == sizeof(MyClonableUserdata)); |
| 200 | *self = *from; | 193 | *self = *from; |
| 201 | } | 194 | } |
| 202 | return 0; | 195 | return 0; |
| @@ -217,7 +210,7 @@ static luaL_Reg const clonable_mt[] = | |||
| 217 | { "set", clonable_set}, | 210 | { "set", clonable_set}, |
| 218 | { "setuv", clonable_setuv}, | 211 | { "setuv", clonable_setuv}, |
| 219 | { "getuv", clonable_getuv}, | 212 | { "getuv", clonable_getuv}, |
| 220 | { NULL, NULL } | 213 | { nullptr, nullptr } |
| 221 | }; | 214 | }; |
| 222 | 215 | ||
| 223 | // ################################################################################################ | 216 | // ################################################################################################ |
| @@ -225,7 +218,7 @@ static luaL_Reg const clonable_mt[] = | |||
| 225 | int luaD_new_clonable( lua_State* L) | 218 | int luaD_new_clonable( lua_State* L) |
| 226 | { | 219 | { |
| 227 | int nuv = (int) luaL_optinteger( L, 1, 1); | 220 | int nuv = (int) luaL_optinteger( L, 1, 1); |
| 228 | lua_newuserdatauv( L, sizeof( struct s_MyClonableUserdata), nuv); | 221 | lua_newuserdatauv( L, sizeof(MyClonableUserdata), nuv); |
| 229 | luaL_setmetatable( L, "clonable"); | 222 | luaL_setmetatable( L, "clonable"); |
| 230 | return 1; | 223 | return 1; |
| 231 | } | 224 | } |
| @@ -237,7 +230,7 @@ static luaL_Reg const deep_module[] = | |||
| 237 | { | 230 | { |
| 238 | { "new_deep", luaD_new_deep}, | 231 | { "new_deep", luaD_new_deep}, |
| 239 | { "new_clonable", luaD_new_clonable}, | 232 | { "new_clonable", luaD_new_clonable}, |
| 240 | { NULL, NULL} | 233 | { nullptr, nullptr } |
| 241 | }; | 234 | }; |
| 242 | 235 | ||
| 243 | // ################################################################################################ | 236 | // ################################################################################################ |
diff --git a/deep_test/deep_test.vcxproj b/deep_test/deep_test.vcxproj index 730c137..1b4f57b 100644 --- a/deep_test/deep_test.vcxproj +++ b/deep_test/deep_test.vcxproj | |||
| @@ -675,11 +675,11 @@ | |||
| 675 | </Link> | 675 | </Link> |
| 676 | </ItemDefinitionGroup> | 676 | </ItemDefinitionGroup> |
| 677 | <ItemGroup> | 677 | <ItemGroup> |
| 678 | <ClCompile Include="..\src\compat.c" /> | 678 | <ClCompile Include="..\src\compat.cpp" /> |
| 679 | <ClCompile Include="..\src\deep.c" /> | 679 | <ClCompile Include="..\src\deep.cpp" /> |
| 680 | <ClCompile Include="..\src\tools.c" /> | 680 | <ClCompile Include="..\src\tools.cpp" /> |
| 681 | <ClCompile Include="..\src\universe.c" /> | 681 | <ClCompile Include="..\src\universe.cpp" /> |
| 682 | <ClCompile Include="deep_test.c" /> | 682 | <ClCompile Include="deep_test.cpp" /> |
| 683 | </ItemGroup> | 683 | </ItemGroup> |
| 684 | <ItemGroup> | 684 | <ItemGroup> |
| 685 | <ClInclude Include="..\src\compat.h" /> | 685 | <ClInclude Include="..\src\compat.h" /> |
diff --git a/deep_test/deep_test.vcxproj.filters b/deep_test/deep_test.vcxproj.filters index be47da9..814301f 100644 --- a/deep_test/deep_test.vcxproj.filters +++ b/deep_test/deep_test.vcxproj.filters | |||
| @@ -15,21 +15,21 @@ | |||
| 15 | </Filter> | 15 | </Filter> |
| 16 | </ItemGroup> | 16 | </ItemGroup> |
| 17 | <ItemGroup> | 17 | <ItemGroup> |
| 18 | <ClCompile Include="deep_test.c"> | 18 | <ClCompile Include="..\src\compat.cpp"> |
| 19 | <Filter>Source Files</Filter> | ||
| 20 | </ClCompile> | ||
| 21 | <ClCompile Include="..\src\deep.c"> | ||
| 22 | <Filter>Lanes</Filter> | 19 | <Filter>Lanes</Filter> |
| 23 | </ClCompile> | 20 | </ClCompile> |
| 24 | <ClCompile Include="..\src\universe.c"> | 21 | <ClCompile Include="..\src\deep.cpp"> |
| 25 | <Filter>Lanes</Filter> | 22 | <Filter>Lanes</Filter> |
| 26 | </ClCompile> | 23 | </ClCompile> |
| 27 | <ClCompile Include="..\src\compat.c"> | 24 | <ClCompile Include="..\src\tools.cpp"> |
| 28 | <Filter>Lanes</Filter> | 25 | <Filter>Lanes</Filter> |
| 29 | </ClCompile> | 26 | </ClCompile> |
| 30 | <ClCompile Include="..\src\tools.c"> | 27 | <ClCompile Include="..\src\universe.cpp"> |
| 31 | <Filter>Lanes</Filter> | 28 | <Filter>Lanes</Filter> |
| 32 | </ClCompile> | 29 | </ClCompile> |
| 30 | <ClCompile Include="deep_test.cpp"> | ||
| 31 | <Filter>Source Files</Filter> | ||
| 32 | </ClCompile> | ||
| 33 | </ItemGroup> | 33 | </ItemGroup> |
| 34 | <ItemGroup> | 34 | <ItemGroup> |
| 35 | <ClInclude Include="..\src\deep.h"> | 35 | <ClInclude Include="..\src\deep.h"> |
