lua-users home
lua-l archive

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


Duncan Cross, 06.11.2010 14:08:
On Sat, Nov 6, 2010 at 11:03 AM, Stefan Behnel wrote:
I'm building the cclosure anyway. So all I really have
to do is put the wrapped iterator userdata into the cclosure and read it
from there using a plain lua_touserdata().

Doing that makes the iterator almost 3x as fast as before.

Is this considered safe, in the sense that it can't be misused from Lua
code? For example, can you extract the underlying C function from its
closure and call it with a new closure?

I don't believe there's any way to create a new closure from an
existing function "prototype" in Lua code (you probably can with the C
API, though). With the debug library available, you can get and set
upvalues for an existing closure, but that's kind of the nature of the
debug library: it will *let* you do unsafe things, and screw yourself
over, in many ways. Users that don't know what they're doing should be
avoiding it and untrusted code shouldn't have access to it anyway.

Cool, that's all I needed to know. Thanks again!

Stefan