Skip to content

Instantly share code, notes, and snippets.

@arch-jslin
Forked from gaspard/simple_jit.lua
Created November 18, 2011 14:56
Show Gist options
  • Save arch-jslin/1376663 to your computer and use it in GitHub Desktop.
Save arch-jslin/1376663 to your computer and use it in GitHub Desktop.
Testing Luajit bindings to C++
local ffi = require 'ffi'
local C = ffi.C
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 C.Simple_id(self.super, ...)
end
local function Simple(...)
local self = {super = C.Simple_Simple(...)}
ffi.gc(self.super, C.Simple__gc)
return setmetatable(self, mt)
end
s = Simple(6)
print(s:id())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment