diff options
author | Benoit Germain <bnt.germain@gmail.com> | 2018-11-30 11:13:21 +0100 |
---|---|---|
committer | Benoit Germain <bnt.germain@gmail.com> | 2018-11-30 11:13:21 +0100 |
commit | b33d86abb9997c1c056d2f6e55a9754dffed5f48 (patch) | |
tree | 63dc7e24d0abe2a5121a196063c6e8866e1f02bc /deep_test | |
parent | c64ad48fdf3aa9505fcf8505c832d1e397d60e85 (diff) | |
download | lanes-b33d86abb9997c1c056d2f6e55a9754dffed5f48.tar.gz lanes-b33d86abb9997c1c056d2f6e55a9754dffed5f48.tar.bz2 lanes-b33d86abb9997c1c056d2f6e55a9754dffed5f48.zip |
Fix clonable userdata uservalue transfer
Diffstat (limited to 'deep_test')
-rw-r--r-- | deep_test/deep_test.c | 27 | ||||
-rw-r--r-- | deep_test/deep_test.vcxproj | 8 | ||||
-rw-r--r-- | deep_test/deep_test.vcxproj.filters | 6 | ||||
-rw-r--r-- | deep_test/deep_test.vcxproj.user | 2 | ||||
-rw-r--r-- | deep_test/deeptest.lua | 13 |
5 files changed, 47 insertions, 9 deletions
diff --git a/deep_test/deep_test.c b/deep_test/deep_test.c index 7edd33f..9585a3c 100644 --- a/deep_test/deep_test.c +++ b/deep_test/deep_test.c | |||
@@ -6,6 +6,7 @@ | |||
6 | #include "lauxlib.h" | 6 | #include "lauxlib.h" |
7 | 7 | ||
8 | #include "deep.h" | 8 | #include "deep.h" |
9 | #include "compat.h" | ||
9 | 10 | ||
10 | #if (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) | 11 | #if (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) |
11 | #define LANES_API __declspec(dllexport) | 12 | #define LANES_API __declspec(dllexport) |
@@ -123,6 +124,27 @@ static int clonable_set( lua_State* L) | |||
123 | 124 | ||
124 | // ################################################################################################ | 125 | // ################################################################################################ |
125 | 126 | ||
127 | static int clonable_setuv( lua_State* L) | ||
128 | { | ||
129 | struct s_MyClonableUserdata* self = (struct s_MyClonableUserdata*) lua_touserdata( L, 1); | ||
130 | int uv = (int) luaL_optinteger( L, 2, 1); | ||
131 | lua_settop( L, 3); | ||
132 | lua_pushboolean( L, lua_setiuservalue( L, 1, uv) != 0); | ||
133 | return 1; | ||
134 | } | ||
135 | |||
136 | // ################################################################################################ | ||
137 | |||
138 | static int clonable_getuv( lua_State* L) | ||
139 | { | ||
140 | struct s_MyClonableUserdata* self = (struct s_MyClonableUserdata*) lua_touserdata( L, 1); | ||
141 | int uv = (int) luaL_optinteger( L, 2, 1); | ||
142 | lua_getiuservalue( L, 1, uv); | ||
143 | return 1; | ||
144 | } | ||
145 | |||
146 | // ################################################################################################ | ||
147 | |||
126 | static int clonable_tostring(lua_State* L) | 148 | static int clonable_tostring(lua_State* L) |
127 | { | 149 | { |
128 | struct s_MyClonableUserdata* self = (struct s_MyClonableUserdata*) lua_touserdata( L, 1); | 150 | struct s_MyClonableUserdata* self = (struct s_MyClonableUserdata*) lua_touserdata( L, 1); |
@@ -170,6 +192,8 @@ static luaL_Reg const clonable_mt[] = | |||
170 | { "__gc", clonable_gc}, | 192 | { "__gc", clonable_gc}, |
171 | { "__lanesclone", clonable_lanesclone}, | 193 | { "__lanesclone", clonable_lanesclone}, |
172 | { "set", clonable_set}, | 194 | { "set", clonable_set}, |
195 | { "setuv", clonable_setuv}, | ||
196 | { "getuv", clonable_getuv}, | ||
173 | { NULL, NULL } | 197 | { NULL, NULL } |
174 | }; | 198 | }; |
175 | 199 | ||
@@ -177,7 +201,8 @@ static luaL_Reg const clonable_mt[] = | |||
177 | 201 | ||
178 | int luaD_new_clonable( lua_State* L) | 202 | int luaD_new_clonable( lua_State* L) |
179 | { | 203 | { |
180 | lua_newuserdata( L, sizeof( struct s_MyClonableUserdata)); | 204 | int nuv = (int) luaL_optinteger( L, 1, 1); |
205 | lua_newuserdatauv( L, sizeof( struct s_MyClonableUserdata), nuv); | ||
181 | luaL_setmetatable( L, "clonable"); | 206 | luaL_setmetatable( L, "clonable"); |
182 | return 1; | 207 | return 1; |
183 | } | 208 | } |
diff --git a/deep_test/deep_test.vcxproj b/deep_test/deep_test.vcxproj index 110a191..d94b855 100644 --- a/deep_test/deep_test.vcxproj +++ b/deep_test/deep_test.vcxproj | |||
@@ -65,7 +65,7 @@ | |||
65 | <CharacterSet>MultiByte</CharacterSet> | 65 | <CharacterSet>MultiByte</CharacterSet> |
66 | </PropertyGroup> | 66 | </PropertyGroup> |
67 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release 5.3|x64'" Label="Configuration"> | 67 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release 5.3|x64'" Label="Configuration"> |
68 | <ConfigurationType>Application</ConfigurationType> | 68 | <ConfigurationType>DynamicLibrary</ConfigurationType> |
69 | <UseDebugLibraries>false</UseDebugLibraries> | 69 | <UseDebugLibraries>false</UseDebugLibraries> |
70 | <PlatformToolset>v141</PlatformToolset> | 70 | <PlatformToolset>v141</PlatformToolset> |
71 | <WholeProgramOptimization>true</WholeProgramOptimization> | 71 | <WholeProgramOptimization>true</WholeProgramOptimization> |
@@ -132,6 +132,10 @@ | |||
132 | <AdditionalDependencies>lua53.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies> | 132 | <AdditionalDependencies>lua53.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies> |
133 | <AdditionalLibraryDirectories>$(SolutionDir)..\lualib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | 133 | <AdditionalLibraryDirectories>$(SolutionDir)..\lualib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> |
134 | </Link> | 134 | </Link> |
135 | <PostBuildEvent> | ||
136 | <Command>xcopy /R /F /Y /I "$(TargetPath)" $(SolutionDir)..\framework\</Command> | ||
137 | <Message>Copy to framework</Message> | ||
138 | </PostBuildEvent> | ||
135 | </ItemDefinitionGroup> | 139 | </ItemDefinitionGroup> |
136 | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug 5.3|Win32'"> | 140 | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug 5.3|Win32'"> |
137 | <ClCompile> | 141 | <ClCompile> |
@@ -224,11 +228,13 @@ | |||
224 | </Link> | 228 | </Link> |
225 | </ItemDefinitionGroup> | 229 | </ItemDefinitionGroup> |
226 | <ItemGroup> | 230 | <ItemGroup> |
231 | <ClCompile Include="..\src\compat.c" /> | ||
227 | <ClCompile Include="..\src\deep.c" /> | 232 | <ClCompile Include="..\src\deep.c" /> |
228 | <ClCompile Include="..\src\universe.c" /> | 233 | <ClCompile Include="..\src\universe.c" /> |
229 | <ClCompile Include="deep_test.c" /> | 234 | <ClCompile Include="deep_test.c" /> |
230 | </ItemGroup> | 235 | </ItemGroup> |
231 | <ItemGroup> | 236 | <ItemGroup> |
237 | <ClInclude Include="..\src\compat.h" /> | ||
232 | <ClInclude Include="..\src\deep.h" /> | 238 | <ClInclude Include="..\src\deep.h" /> |
233 | <ClInclude Include="..\src\universe.h" /> | 239 | <ClInclude Include="..\src\universe.h" /> |
234 | </ItemGroup> | 240 | </ItemGroup> |
diff --git a/deep_test/deep_test.vcxproj.filters b/deep_test/deep_test.vcxproj.filters index b5c696f..93f6148 100644 --- a/deep_test/deep_test.vcxproj.filters +++ b/deep_test/deep_test.vcxproj.filters | |||
@@ -24,6 +24,9 @@ | |||
24 | <ClCompile Include="..\src\universe.c"> | 24 | <ClCompile Include="..\src\universe.c"> |
25 | <Filter>Lanes</Filter> | 25 | <Filter>Lanes</Filter> |
26 | </ClCompile> | 26 | </ClCompile> |
27 | <ClCompile Include="..\src\compat.c"> | ||
28 | <Filter>Lanes</Filter> | ||
29 | </ClCompile> | ||
27 | </ItemGroup> | 30 | </ItemGroup> |
28 | <ItemGroup> | 31 | <ItemGroup> |
29 | <ClInclude Include="..\src\deep.h"> | 32 | <ClInclude Include="..\src\deep.h"> |
@@ -32,6 +35,9 @@ | |||
32 | <ClInclude Include="..\src\universe.h"> | 35 | <ClInclude Include="..\src\universe.h"> |
33 | <Filter>Lanes</Filter> | 36 | <Filter>Lanes</Filter> |
34 | </ClInclude> | 37 | </ClInclude> |
38 | <ClInclude Include="..\src\compat.h"> | ||
39 | <Filter>Lanes</Filter> | ||
40 | </ClInclude> | ||
35 | </ItemGroup> | 41 | </ItemGroup> |
36 | <ItemGroup> | 42 | <ItemGroup> |
37 | <None Include="deeptest.lua"> | 43 | <None Include="deeptest.lua"> |
diff --git a/deep_test/deep_test.vcxproj.user b/deep_test/deep_test.vcxproj.user index 372bf91..f6a2db8 100644 --- a/deep_test/deep_test.vcxproj.user +++ b/deep_test/deep_test.vcxproj.user | |||
@@ -3,7 +3,7 @@ | |||
3 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug 5.3|x64'"> | 3 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug 5.3|x64'"> |
4 | <LocalDebuggerCommand>D:\Boulot\anubis\Lua\framework\lua53.exe</LocalDebuggerCommand> | 4 | <LocalDebuggerCommand>D:\Boulot\anubis\Lua\framework\lua53.exe</LocalDebuggerCommand> |
5 | <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> | 5 | <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> |
6 | <LocalDebuggerCommandArguments>-i deeptest.lua</LocalDebuggerCommandArguments> | 6 | <LocalDebuggerCommandArguments>-i -- deeptest.lua</LocalDebuggerCommandArguments> |
7 | <LocalDebuggerWorkingDirectory>D:\Boulot\anubis\Lua\bindings\Lanes\lanes\deep_test\</LocalDebuggerWorkingDirectory> | 7 | <LocalDebuggerWorkingDirectory>D:\Boulot\anubis\Lua\bindings\Lanes\lanes\deep_test\</LocalDebuggerWorkingDirectory> |
8 | </PropertyGroup> | 8 | </PropertyGroup> |
9 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug 5.4|x64'"> | 9 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug 5.4|x64'"> |
diff --git a/deep_test/deeptest.lua b/deep_test/deeptest.lua index c0bbab4..16059d9 100644 --- a/deep_test/deeptest.lua +++ b/deep_test/deeptest.lua | |||
@@ -4,16 +4,17 @@ local l = lanes.linda "my linda" | |||
4 | -- we will transfer userdata created by this module, so we need to make Lanes aware of it | 4 | -- we will transfer userdata created by this module, so we need to make Lanes aware of it |
5 | local dt = lanes.require "deep_test" | 5 | local dt = lanes.require "deep_test" |
6 | 6 | ||
7 | local test_deep = true | 7 | local test_deep = false |
8 | local test_clonable = false | 8 | local test_clonable = true |
9 | 9 | ||
10 | local performTest = function( obj_) | 10 | local performTest = function( obj_) |
11 | obj_:set(666) | 11 | obj_:set( 666) |
12 | obj_:setuv( 1, "my uservalue") | ||
12 | print( "immediate:", obj_) | 13 | print( "immediate:", obj_) |
13 | 14 | ||
14 | l:set( "key", obj_) | 15 | l:set( "key", obj_) |
15 | local out = l:get( "key") | 16 | local out = l:get( "key") |
16 | print( "out of linda:", out) | 17 | print( "out of linda:", out, out:getuv( 1)) |
17 | 18 | ||
18 | local g = lanes.gen( | 19 | local g = lanes.gen( |
19 | "package" | 20 | "package" |
@@ -21,13 +22,13 @@ local performTest = function( obj_) | |||
21 | required = { "deep_test"} -- we will transfer userdata created by this module, so we need to make this lane aware of it | 22 | required = { "deep_test"} -- we will transfer userdata created by this module, so we need to make this lane aware of it |
22 | } | 23 | } |
23 | , function( obj_) | 24 | , function( obj_) |
24 | print( "in lane:", obj_) | 25 | print( "in lane:", obj_, obj_:getuv( 1)) |
25 | return obj_ | 26 | return obj_ |
26 | end | 27 | end |
27 | ) | 28 | ) |
28 | h = g( obj_) | 29 | h = g( obj_) |
29 | local from_lane = h[1] | 30 | local from_lane = h[1] |
30 | print( "from lane:", from_lane) | 31 | print( "from lane:", from_lane, from_lane:getuv( 1)) |
31 | end | 32 | end |
32 | 33 | ||
33 | if test_deep then | 34 | if test_deep then |