lua-users home
lua-l archive

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


Michael Panetta wrote:

But this does not work, because when lua_dump creates the
chunk, the upvalue gets lost.  Does anyone know of a way
to do something almost as simple (I would like to make it
so that all the marshalling is done in lua, not C) to get
the data through?

You can use debug.getupvalue to get the values of the
upvalues from the original function, and then save them to
be reset with debug.setupvalue after reloading the dumped
chunk.  This would not honor shared upvalues -- two
functions that share an upvalue would end up having two
independent upvalues.

(It's basically impossible to honor shared upvalues and
still implement this in pure Lua: the only way to even tell
whether two upvalues are the same variable is to set one and
see if the other changes, and the only way [that I can think
of] to get two chunks to act like their upvalues are shared
would be some nasty hack that checks whether the upvalues'
values have been changed after every instruction.)

The Pluto library (which does its heavy lifting in C, and
which you can check out once LuaForge is back up) does this
in full generality, honoring shared upvalues.

By the way, "marshall" is the correct spelling (you used
"martial" a couple times).

--
Aaron