lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 31 March 2017 at 20:06, William Ahern <william@25thandclement.com> wrote:
> Any key or
> value object you add to the table is copied, including tables, strings, and
> userdata, inheriting the "t" mode or an analagous attribute. (Anything read
> from the table is copied out, dropping the attribute.)


This would be very easy to do with an external module, no need to add
to the language itself.  Just set some dictionary structure and store
serialized values.  For example, that's what OpenResty shared
dictionaries [1] do.  You can only store simple values (booleans,
numbers and strings), your "copying in / out" is just serializing a
"complex" value into a binary string, for example using msgpack or
CBOR.

Still, there are some data types that aren't easy to copy from an
interpreter to another, like functions, or tables that hold references
to stuff that you want to keep outside of the "message".  The
serialization part can be circumvented by some "methods", like the
__copy you propose; but to deserialize arbitrary types of data you'd
have to allow user-specified type tagging and register deserialization
handlers.


[1]: https://github.com/openresty/lua-nginx-module#ngxshareddict

-- 
Javier