Last active
April 12, 2016 21:20
-
-
Save cablehead/29c65b2047a165731063fd998e91b5ea to your computer and use it in GitHub Desktop.
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([[ | |
| 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