I'm working on wraping libcurl in luajit ffi. My finalizer isn't getting called.
local ffi = require("ffi")
ffi.cdef [[
typedef struct{} CURL;
CURL * curl_easy_init();
void curl_easy_cleanup(CURL *);
]]
local CURL_lib = ffi.load("../lib/libcurl.so")
local CURL_CTX
local CURL_CTX_mt = {
__gc = function() print "finalizing"; CURL_lib.curl_easy_cleanup(CURL_CTX); end
}
ffi.metatype("CURL", CURL_CTX_mt)
CURL_CTX = ffi.new("CURL[1]")
CURL_CTX = CURL_lib.curl_easy_init();
print "done"
What am I missing here ? :D
BTW CURL is defined as typedef void CURL;
I'm sure the way I am trying to do it isn't clean enough. Any advice ?
eureka ! : self answer -- still interested in comments if there any glaring issues.