[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How to exchange the values of a specific variable (e.g: maybe a table) between Lua_States?
- From: Robert Burke <sharpobject@...>
- Date: Fri, 23 Apr 2021 19:27:11 +0900
On Fri, Apr 23, 2021 at 7:10 PM 孙世龙 sunshilong <firstname.lastname@example.org> 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
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. I used this one at work a