lua-users home
lua-l archive

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


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.

--Mike