lua-users home
lua-l archive

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



There's been request to have full closure copying between detached Lua states. I think this can currently be done for C-based closures, but not for Lua ones.

What I mean by closure copying is:

- get the number of upvalues in source state, and their values (ok, lua_getupvalue) - create same function in target state, with values of the upvalues copied (ok, lua_pushcclosure)

Normally, the upvalues will have separate lives after the copying. One state modifying will not modify the other state. However, using a communications userdata as upvalue can indeed be made to act as a shared, modifiable resource, so in that way even upvalues could be made shared.

The problems are:

- is the order of upvalues given by 'lua_getupvalue' the same as expected by 'lua_pushcclosure'? I guess it is, but haven't tested in action, yet.

- string.dump (which I'm using for Lua function dump) is said to:

<<
Returns a string containing a binary representation of the given function, so that a later loadstring on this string returns a copy of the function. function must be a Lua function without upvalues.

<<

Could future Lua have a mechanism similar to 'lua_pushcclosure' for Lua functions? Is there some reason why this cannot (ever) be done?


-asko