-
-
Save arch-jslin/1376663 to your computer and use it in GitHub Desktop.
Testing Luajit bindings to C++
This file contains hidden or 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
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