From c52571736d852d2636bd285d19c613be5c706cff Mon Sep 17 00:00:00 2001
From: Benoit Germain
Date: Sat, 20 Sep 2025 14:30:57 +0200
Subject: Improve table and userdata conversions
* add convert_fallback and convert_max_attempts to global settings
* if no __lanesconvert is available, use convert_fallback (can be useful for externally provided full userdata with fixed metatables)
* only try conversion on non-deep and non-clonable userdata
* conversion can be applied recursively, up to convert_max_attempts times
* plus all the relevant unit tests of course
---
docs/index.html | 33 ++++++++++++++++++++++++++++++---
1 file changed, 30 insertions(+), 3 deletions(-)
(limited to 'docs')
diff --git a/docs/index.html b/docs/index.html
index 2e74495..0d24d55 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -71,7 +71,7 @@
- This document was revised on 03-Jul-25, and applies to version 4.0.0.
+ This document was revised on 19-Sep-25, and applies to version 4.0.0.
@@ -387,6 +387,30 @@
+
+
+ .convert_fallback
+ |
+
+ nil, lanes.null or 'decay'
+ |
+
+ Same as __lanesconvert (see Limitations on data passing), but cannot be a function, because this would have to be transferred to all newly created lanes.
+ |
+
+
+
+
+ .convert_max_attempts
+ |
+
+ 1 ≥ number ≥ 9
+ |
+
+ When a table or userdata conversion is performed with a function, it can happen recursively up to this number of attempts before triggering an error. Default is 1.
+ |
+
+
.internal_allocator
@@ -1801,11 +1825,14 @@
Using the same source table in multiple linda messages keeps no ties between the tables (this is the same reason why tables can't be used as slots).
- For tables and full userdata: before anything else, the metatable is searched for a __lanesconvert field. If found, the source object is converted as follows depending on __lanesconvert's value:
+ For tables and full userdata that are neither deep nor clonable: before anything else, a converter is searched for in the __lanesconvert field of its metatable.
+ If there is no metatable, or no __lanesconvert, convert_fallback is used instead.
+ The source object is then converted depending on the converter value:
+ - nil: The value is not converted. If it is not a clonable or deep userdata, the transfer will eventually fail with an error.
- lanes.null: The value is converted to nil.
- "decay": The value is converted to a light userdata obtained from lua_topointer().
- - A function: The function is called as o:__lanesconvert(string), where the argument is either "keeper" or "regular", depending on the type of destination. Its (single) return value is the result of the conversion.
+ - A function: The function is called as o:__lanesconvert(string), where the argument is either "keeper" (sending data in a Linda) or "regular" (when creating or calling a Lane generator). Its first return value is the result of the conversion, the rest is ignored. Transfer is then attempted on the new value. If this also requires a conversion, it will be done, up to a depth of 3, after which an error will be raised.
- Any other value raises an error.
--
cgit v1.2.3-55-g6feb
|