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/deep_test.c | |
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/deep_test.c')
-rw-r--r-- | deep_test/deep_test.c | 27 |
1 files changed, 26 insertions, 1 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 | } |