Created
July 17, 2011 09:05
Testing Luajit bindings to C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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