[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [ANN] LuaJIT-2.0.0-beta8
- From: Mike Pall <mikelu-1106@...>
- Date: Fri, 24 Jun 2011 11:17:40 +0200
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.
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. You can
create the needed tables lazily by scanning the standard module
tables as needed. This approach doesn't cover dynamically created
closures, e.g. iterators from the io or string libraries. However,
copying a 'live' iterator is not a good idea, anyway.