Skip to content

Instantly share code, notes, and snippets.

@gaspard
Created July 17, 2011 09:05

Revisions

  1. gaspard revised this gist Jul 17, 2011. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions simple_jit.lua
    Original file line number Diff line number Diff line change
    @@ -4,11 +4,11 @@ ffi = require 'ffi'
    simple = ffi.load('simple')

    ffi.cdef[[
    typedef struct { void *__this; } Simple;
    typedef struct Simple Simple;

    Simple *Simple_Simple(int id);
    void Simple__gc(void *__this);
    int Simple_id(void *__this);
    Simple *Simple_Simple(int);
    void Simple__gc(Simple *);
    int Simple_id(Simple *);
    ]]

    -- wrap into class like behavior
  2. gaspard created this gist Jul 17, 2011.
    28 changes: 28 additions & 0 deletions simple_jit.lua
    Original 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())