lua-users home
lua-l archive

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


2011/6/24 Mike Pall <mikelu-1106@mike.de>:
> Benoit Germain wrote:
>> But if it is not a C function, and it is not a Lua function, what is
>> it, and how can I copy it from one state to another?
>
> It's an internal assembler function. And no, you can't 'copy' it.
>
> In general it's not safe to assume you can copy C closures between
> different state, by just copying their addresses. They might hold
> on to state-specific upvalues or reference static data. Or other
> closures may depend on the exact identity of a closure.
>

For C static data there isn't much that I can do besides relying on
the user knowing what he is doing.
Upvalues are taken care of. Exact identity isn't preserved in Lanes
anyway since a lane is totally separate, everything is copied by
value. Therefore the identity of all complex values (closures, tables)
is lost.
However, full userdata identity is preserved as long as the copied
userdata are implemented in a special way that creates a dependence
with the Lanes module. Thread-safety should be taken care of the this
userdata's implementation. Unknown userdata generate an error when
copied.

> The only portable solution would be to identify the internal
> function in one state and then pick the same function in another
> state, e.g. by using an inverted table in both states.

All right, but how can I do this when LuaJIT's lua_tocfunction returns
NULL for these functions? How can I differentiate them? Is there
anything else than a string "fast#NN" in the lua_Debug structure?


-- 
Benoit.