lune/tests/ffi/external_closure/callClosure.luau
2024-11-13 06:20:28 +00:00

13 lines
556 B
Text

local callableWrapper = require("../utils/callableWrapper")
local ffi = require("@lune/ffi")
local lib = require("../utils/compile")("./tests/ffi/external_closure/lib.c")
local c = ffi.c
-- Create closure
local closure = c.fn({ c.int, c.int }, c.int):closure(function(ret, a, b)
c.int:writeData(ret, c.int:readData(a) + c.int:readData(b))
end)
local callClosure = callableWrapper(lib:find("call_closure"), { c.void:ptr() }, c.int)
local result = callClosure(closure:ref())
assert(result == 72, `callClosure failed. result expected 20000, got {result}`)