Skip to content

Instantly share code, notes, and snippets.

@anna-bucher
Created July 17, 2011 09:05
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anna-bucher/1087382 to your computer and use it in GitHub Desktop.
Save anna-bucher/1087382 to your computer and use it in GitHub Desktop.
Testing Luajit bindings to C++
-- 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())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment