Created
July 17, 2011 09:05
Revisions
-
gaspard revised this gist
Jul 17, 2011 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,11 +4,11 @@ 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 -
gaspard created this gist
Jul 17, 2011 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ -- luajit simple_jit.lua ffi = require 'ffi' simple = ffi.load('simple') ffi.cdef[[ typedef struct { void *__this; } Simple; Simple *Simple_Simple(int id); void Simple__gc(void *__this); int Simple_id(void *__this); ]] -- 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())