[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LuaJIT 2 ffi (casting / force hotpath)
- From: Mike Pall <mikelu-1101@...>
- Date: Fri, 21 Jan 2011 12:47:32 +0100
Alex Bradbury wrote:
> I can imagine binding C APIs by creating Lua objects that hold a
> reference to the C object. If the library lets you allocate the memory
> yourself, then garbage collection can be handled for you. Otherwise
> just the pointer cdata will be gced, so you must write your own __gc
> metamethod to call the library's free function - but this isn't
> supported on tables. Is there a better way than creating a newproxy
> for each object and giving it a __gc metamethod that makes the
> appropriate free call?
You raise a valid point. Currently wrapping it in userdata is the
only way to trigger the __gc metamethod. Although cdata objects
will gain user-definable metamethods (per type, not per instance),
the __gc metamethod won't work on them with the current GC. You'll
have to wait for LuaJIT 2.1.
--Mike