lua-users home
lua-l archive

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


On 7/28/05, Nevo Hed <nhed@navic.tv> wrote:
> It looks to me like you would be able to serialize whatever code you want to
> run in
> the other environment just with string.dump()
> 
> Pluto looks great - but might be an overkill for simple uses (i.e. sending
> ''events'' to other lua environments)

string.dump() won't serialize functions with upvalues, so it's not
especially useful for this sort of thing. In order to use it for this,
you pretty much have to build up a function's source code using
string-functions and then compile it (sort of a poor man's
closure).... and for events nontrivial enough that you have to move
data over, that *IS* overkill. ;-)

> That said, we heard here that lua_xmove is intended for threads of
> the same parent environment, ok, is there anything specific about xmove's
> implementation that prevents use by unrelated environments?
> 
> Is the only thing I am risking that there will be an invalid object
> reference?

Pretty much, yeah. Non-GC values are fully contained in the stack.
That means numbers, booleans, and lightuserdatas. If you move strings
over with lua_xmove, you will run into problems, since you'll have a
reference from a string in one state to the string table of the other
state. Of course, if you know you're only serializing a string, you
could just do lua_getstring and lua_pushstring to avoid these issues.

BTW, for a slightly more featureful version of the serialize code you
posted, check out "pickle" on the Wiki. A bit obfuscated (and, IIRC,
written for 4.0), but rather elegant.

Ben