mirror of
https://github.com/lune-org/lune.git
synced 2025-04-04 10:30:54 +01:00
13 lines
556 B
Text
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}`)
|