Skip to content

Instantly share code, notes, and snippets.

@cablehead
Last active April 12, 2016 21:20
Show Gist options
  • Select an option

  • Save cablehead/29c65b2047a165731063fd998e91b5ea to your computer and use it in GitHub Desktop.

Select an option

Save cablehead/29c65b2047a165731063fd998e91b5ea to your computer and use it in GitHub Desktop.
local ffi = require("ffi")
local C = ffi.C
ffi.cdef([[
unsigned int
sleep(unsigned int seconds); ]])
local function foo(no)
print("FOO:", no)
C.sleep(1)
print("FOO:", no)
end
local R_mt = {}
R_mt.__index = R_mt
local function R(no)
local self = setmetatable({}, R_mt)
self.__gc = ffi.new("int[1]")
ffi.gc(self.__gc, function() foo(no) end)
self.no = no
return self
end
local function main()
local r = R(3)
end
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment