lune/tests/ffi/external_pointer/init.luau
2024-10-24 04:52:11 +00:00

20 lines
567 B
Text

local ffi = require("@lune/ffi")
local c = ffi.c
local testdir = "./tests/ffi/external_pointer"
local compile = require("../utility/compile")
compile(`{testdir}/lib.c`, `{testdir}/lib.so`)
local lib = ffi.open(`{testdir}/lib.so`)
local function test_pointerWrite()
local pointerWrite = c.fn({ c.int:ptr() }, c.void):callable(lib:find("pointer_write"))
local aBox = ffi.box(c.int.size)
pointerWrite(nil, aBox:ref():ref())
local result = c.int:readData(aBox)
assert(result == 123, `pointer failed. result expected 123, got {result}`)
end
test_pointerWrite()