[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: LuaJIT FFI and __gc metatable
- From: Pavel Roschin <rpg89@...>
- Date: Tue, 3 Apr 2012 21:52:55 +0400
I'm trying to create userdata in library (struct Image) and collect it
using __gc metamethod:
C code:
Image * newImage() {
ptr = malloc(...);
return ptr;
}
void deleteImage(Image * ptr) {
//do something
free(ptr->internal_data);
}
Lua code:
ffi.metatype('Image', {
__index = {
draw = lib.imageDraw
},
__gc = lib.deleteImage
})
Using image:
local ptr = ffi.new('Image')
ptr:draw() --works
ptr = nil --works perfectly, lib.deleteImage works
-------------------------
local ptr = lib.newImage()
ptr:draw() --works as previous
ptr = nil --here is no __gc call!
collectgarbage() --still nothing
I use libraries, that generate many dynamic structures, is there a way
to connect library's finalizers with gc?
--
RPG