From d1ef9b97e356805c622e4832ec76289bae391a6e Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Wed, 23 Jun 2021 12:38:01 +0200 Subject: __lanesclone now receives the original as light userdata the first time it is called --- deep_test/deep_test.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'deep_test') diff --git a/deep_test/deep_test.c b/deep_test/deep_test.c index 9585a3c..61c81c5 100644 --- a/deep_test/deep_test.c +++ b/deep_test/deep_test.c @@ -166,8 +166,12 @@ static int clonable_lanesclone( lua_State* L) { switch( lua_gettop( L)) { - case 0: - lua_pushinteger( L, sizeof( struct s_MyClonableUserdata)); + case 1: + { + // in case we need it to compute the amount of memory we need + struct s_MyClonableUserdata* self = lua_touserdata( L, 1); + lua_pushinteger( L, sizeof( struct s_MyClonableUserdata)); + } return 1; case 2: @@ -175,8 +179,8 @@ static int clonable_lanesclone( lua_State* L) struct s_MyClonableUserdata* self = lua_touserdata( L, 1); struct s_MyClonableUserdata* from = lua_touserdata( L, 2); *self = *from; - return 0; } + return 0; default: (void) luaL_error( L, "Lanes called clonable_lanesclone with unexpected parameters"); @@ -223,7 +227,7 @@ extern int __declspec(dllexport) luaopen_deep_test(lua_State* L) { luaL_newlib( L, deep_module); // M - // preregister the metatables for the types we can instanciate so that Lanes can know about them + // preregister the metatables for the types we can instantiate so that Lanes can know about them if( luaL_newmetatable( L, "clonable")) // M mt { luaL_setfuncs( L, clonable_mt, 0); -- cgit v1.2.3-55-g6feb