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

15 lines
663 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 closureWithPointer = c.fn({ c.int, c.int:ptr() }, c.int)
:closure(function(returnRef, aRef, bRef)
c.int:writeData(returnRef, c.int:readData(aRef) + c.int:readData(bRef:deref()))
end)
local callClosureWithPointer =
callableWrapper(lib:find("call_closure_with_pointer"), { c.void:ptr() }, c.int)
local result = callClosureWithPointer(closureWithPointer:ref())
assert(result == 72, `closureWithPointer failed. result expected 20000, got {result}`)