lua-users home
lua-l archive

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


I had skipped luaF_newCclosure because it used malloc, and I won't be around to clean up. But you're right, GC does that - great.

14.3.2005 kello 23:01, Ben Sunshine-Hill kirjoitti:

On Mon, 14 Mar 2005 22:31:39 +0200, Asko Kauppi <> wrote:

I have the lua_CFunction pointers, of course, but creating a closure
without touching the stack (if I touch the stack, well, BOOOM...) Any
ideas from harder-than-hard core programmers welcome.

Well, I'm the next best thing.... softer-than-hardcore. Ph33r my
moderate programming skillz. ;-)

Creating a closure without touching the stack shouldn't be too
difficult; just manually create the closure with luaF_newCclosure
(this news it with a particular number of upvals, and tells the GC
about it) and then fill the upvals and the function pointer directly.
Pluto does something very much like this, except that it still uses
the stack (though if this were all it were doing, it wouldn't need

One caveat if you can't touch the stack is making sure that stuff
doesn't get GCed out from under you. If you're going to be messing
with objects that are live to you but that aren't linked anywhere from
the root set, you have three choices: either do nothing that could
invoke the GC, temporarily keep the GC from doing anything, or hold
off on linking the object into the GC by not calling luaC_link (note
that luaC_link is called from luaF_new[CL]closure) until it's safe.