diff options
| author | Benoit Germain <bnt.germain@gmail.com> | 2021-06-23 12:38:01 +0200 |
|---|---|---|
| committer | Benoit Germain <bnt.germain@gmail.com> | 2021-06-23 12:38:01 +0200 |
| commit | d1ef9b97e356805c622e4832ec76289bae391a6e (patch) | |
| tree | e00a1a4b1c16bcc02d0e6c75d664d93e76f8d606 /docs | |
| parent | 5875fe44ba7a240dd101f954c7dc83337a0c2cef (diff) | |
| download | lanes-d1ef9b97e356805c622e4832ec76289bae391a6e.tar.gz lanes-d1ef9b97e356805c622e4832ec76289bae391a6e.tar.bz2 lanes-d1ef9b97e356805c622e4832ec76289bae391a6e.zip | |
__lanesclone now receives the original as light userdata the first time it is called
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/index.html | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/docs/index.html b/docs/index.html index 49b862f..e9a313e 100644 --- a/docs/index.html +++ b/docs/index.html | |||
| @@ -64,13 +64,13 @@ | |||
| 64 | <font size="-1"> | 64 | <font size="-1"> |
| 65 | <p> | 65 | <p> |
| 66 | <br/> | 66 | <br/> |
| 67 | <i>Copyright © 2007-19 Asko Kauppi, Benoit Germain. All rights reserved.</i> | 67 | <i>Copyright © 2007-21 Asko Kauppi, Benoit Germain. All rights reserved.</i> |
| 68 | <br/> | 68 | <br/> |
| 69 | Lua Lanes is published under the same <a href="http://en.wikipedia.org/wiki/MIT_License">MIT license</a> as Lua 5.1, 5.2, 5.3 and 5.4. | 69 | Lua Lanes is published under the same <a href="http://en.wikipedia.org/wiki/MIT_License">MIT license</a> as Lua 5.1, 5.2, 5.3 and 5.4. |
| 70 | </p> | 70 | </p> |
| 71 | 71 | ||
| 72 | <p> | 72 | <p> |
| 73 | This document was revised on 26-Apr-19, and applies to version <tt>3.14.0</tt>. | 73 | This document was revised on 23-Jun-21, and applies to version <tt>3.15.0</tt>. |
| 74 | </p> | 74 | </p> |
| 75 | </font> | 75 | </font> |
| 76 | </center> | 76 | </center> |
| @@ -1548,23 +1548,31 @@ events to a common Linda, but... :).</font> | |||
| 1548 | 1548 | ||
| 1549 | <h3 id="clonable_userdata">Clonable full userdata in your own apps</h3> | 1549 | <h3 id="clonable_userdata">Clonable full userdata in your own apps</h3> |
| 1550 | <p> | 1550 | <p> |
| 1551 | Starting with version 3.13.0, a new way of passing full userdata across lanes uses a new <tt>__lanesclone</tt> metamethod. A typical implementation would look like: | 1551 | Starting with version 3.13.0, a new way of passing full userdata across lanes uses a new <tt>__lanesclone</tt> metamethod. |
| 1552 | When a deep userdata is cloned, Lanes calls <tt>__lanesclone</tt> twice, in the context of the source lane.</br> | ||
| 1553 | The first call receives the original as light userdata, as in <tt>ud:__lanesclone()</tt>, and should return the amount of memory used to create the cloned full userdata.</br> | ||
| 1554 | The second call receives the clone and original as light userdata, as in <tt>clone:__lanesclone(original)</tt>, and should perform the actual cloning.</br> | ||
| 1555 | A typical implementation would look like: | ||
| 1552 | <table border="1" bgcolor="#FFFFE0" cellpadding="10" style="width:50%"><tr><td><pre> | 1556 | <table border="1" bgcolor="#FFFFE0" cellpadding="10" style="width:50%"><tr><td><pre> |
| 1553 | static int clonable_lanesclone( lua_State* L) | 1557 | static int clonable_lanesclone( lua_State* L) |
| 1554 | { | 1558 | { |
| 1555 | switch( lua_gettop( L)) | 1559 | switch( lua_gettop( L)) |
| 1556 | { | 1560 | { |
| 1557 | case 0: | 1561 | case 1: // original:__lanesclone() |
| 1558 | lua_pushinteger( L, sizeof( struct s_MyClonableUserdata)); | 1562 | { |
| 1563 | // the original (as light userdata), in case you need it to compute the size of the clone | ||
| 1564 | struct s_MyClonableUserdata* self = lua_touserdata( L, 1); | ||
| 1565 | lua_pushinteger( L, sizeof( struct s_MyClonableUserdata)); | ||
| 1566 | } | ||
| 1559 | return 1; | 1567 | return 1; |
| 1560 | 1568 | ||
| 1561 | case 2: | 1569 | case 2: // clone:__lanesclone(original) |
| 1562 | { | 1570 | { |
| 1563 | struct s_MyClonableUserdata* self = lua_touserdata( L, 1); | 1571 | struct s_MyClonableUserdata* self = lua_touserdata( L, 1); |
| 1564 | struct s_MyClonableUserdata* from = lua_touserdata( L, 2); | 1572 | struct s_MyClonableUserdata* from = lua_touserdata( L, 2); |
| 1565 | *self = *from; | 1573 | *self = *from; |
| 1566 | return 0; | ||
| 1567 | } | 1574 | } |
| 1575 | return 0; | ||
| 1568 | 1576 | ||
| 1569 | default: | 1577 | default: |
| 1570 | (void) luaL_error( L, "Lanes called clonable_lanesclone with unexpected parameters"); | 1578 | (void) luaL_error( L, "Lanes called clonable_lanesclone with unexpected parameters"); |
| @@ -1605,7 +1613,7 @@ int luaopen_deep_test(lua_State* L) | |||
| 1605 | </p> | 1613 | </p> |
| 1606 | 1614 | ||
| 1607 | <p> | 1615 | <p> |
| 1608 | Then a new clonable userdata instance can just do like any non-Lanes aware userdata, as long as its metatable contains the aforementionned <tt>__lanesclone</tt> method. Note that the current implementation doesn't support uservalues on such userdata. | 1616 | Then a new clonable userdata instance can just do like any non-Lanes aware userdata, as long as its metatable contains the aforementionned <tt>__lanesclone</tt> method. |
| 1609 | <table border="1" bgcolor="#FFFFE0" cellpadding="10" style="width:50%"><tr><td><pre> | 1617 | <table border="1" bgcolor="#FFFFE0" cellpadding="10" style="width:50%"><tr><td><pre> |
| 1610 | int luaD_new_clonable( lua_State* L) | 1618 | int luaD_new_clonable( lua_State* L) |
| 1611 | { | 1619 | { |
| @@ -1746,3 +1754,4 @@ int luaD_new_clonable( lua_State* L) | |||
| 1746 | 1754 | ||
| 1747 | </body> | 1755 | </body> |
| 1748 | </html> | 1756 | </html> |
| 1757 | </pre></pre></pre></pre></pre></pre></pre> \ No newline at end of file | ||
