https://gist.github.com/gaspard/1087382
https://gist.github.com/marciol/1983296
-- luajit simple_jit.lua | |
ffi = require 'ffi' | |
simple = ffi.load('simple') | |
ffi.cdef[[ | |
typedef struct Simple Simple; | |
Simple *Simple_Simple(int); | |
void Simple__gc(Simple *); | |
int Simple_id(Simple *); | |
]] | |
-- wrap into class like behavior | |
local mt = {} | |
mt.__index = mt | |
function mt.id(self, ...) | |
return simple.Simple_id(self.super,...) | |
end | |
function Simple(...) | |
local self = {super = simple.Simple_Simple(...)} | |
ffi.gc(self.super, simple.Simple__gc) | |
return setmetatable(self, mt) | |
end | |
s = Simple(6) | |
print(s:id()) |