lua-users home
lua-l archive

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


>From Robert Burke:
>If it is a table that
>refers to state that you don't want to serialize, such as uses of
>metatables to build classes, then you need a scheme for encoding which
>metatable it was on the sending end and resolving that encoded
>metatable reference to the corresponding metatable on the receiving
>end.

Thank you for your detailed explanation.
Why the uses of metatables make things more complicated?
Could you please explain that in more detail for me?

Best Regards
Sunshilong

On Fri, Apr 23, 2021 at 6:27 PM Robert Burke <sharpobject@gmail.com> wrote:
>
> On Fri, Apr 23, 2021 at 7:10 PM 孙世龙 sunshilong <sunshilong369@gmail.com> wrote:
> > How to exchange the values of a specific variable (e.g: maybe a table)
> > between Lua_States? Is there a reliable library could achieve this?
>
> If it is a table, you need to serialize it, send over the encoded
> string, and deserialize it on the receiving end. If it is a table that
> refers to state that you don't want to serialize, such as uses of
> metatables to build classes, then you need a scheme for encoding which
> metatable it was on the sending end and resolving that encoded
> metatable reference to the corresponding metatable on the receiving
> end.
>
> I don't know of any library that attempts to solve even most of this
> problem, but for example love2d's thread module includes the encoding
> and decoding of (presumably acyclic) tables that contain only
> booleans, strings, numbers, love2d's userdata, and tables that also
> meet these constraints.
>
> If you only want to send tables that contain only simple things (so,
> the above, but no userdata), and you only want to send them between
> lua_States, then you can probably use an off-the-shelf encoding and
> decoding library such as lua-cmsgpack[1]. I used this one at work a
> while ago.
>
> [1] https://github.com/antirez/lua-cmsgpack