From 2c0000d5169cacf950d06637ada1a371cf382896 Mon Sep 17 00:00:00 2001
From: Benoit Germain
- This document was revised on 8-Feb-22, and applies to version 3.15.2. + This document was revised on 8-Feb-22, and applies to version 3.16.0.
@@ -1550,27 +1550,20 @@ events to a common Linda, but... :).Starting with version 3.13.0, a new way of passing full userdata across lanes uses a new __lanesclone metamethod. - When a deep userdata is cloned, Lanes calls __lanesclone twice, in the context of the source lane. - The first call receives the original as light userdata, as in ud:__lanesclone(), and should return the amount of memory used to create the cloned full userdata. - The second call receives the clone and original as light userdata, as in clone:__lanesclone(original), and should perform the actual cloning. - A typical implementation would look like: + When a deep userdata is cloned, Lanes calls __lanesclone once, in the context of the source lane. + The call receives the clone and original as light userdata, plus the actual userdata size, as in clone:__lanesclone(original,size), and should perform the actual cloning. + A typical implementation would look like (BEWARE, THIS CHANGED WITH VERSION 3.16.0):
static int clonable_lanesclone( lua_State* L)
{
switch( lua_gettop( L))
{
- case 1: // original:__lanesclone()
- {
- // the original (as light userdata), in case you need it to compute the size of the clone
- struct s_MyClonableUserdata* self = lua_touserdata( L, 1);
- lua_pushinteger( L, sizeof( struct s_MyClonableUserdata));
- }
- return 1;
-
- case 2: // clone:__lanesclone(original)
+ case 3:
{
struct s_MyClonableUserdata* self = lua_touserdata( L, 1);
struct s_MyClonableUserdata* from = lua_touserdata( L, 2);
+ size_t len = lua_tointeger( L, 3);
+ assert( len == sizeof(struct s_MyClonableUserdata));
*self = *from;
}
return 0;
@@ -1736,9 +1729,7 @@ int luaD_new_clonable( lua_State* L)
|