Assuming there is following C code:
struct Foo { int dummy; }
int tryToAllocateFoo(Foo ** dest);
...How to do following in LuaJIT?
Foo * pFoo = NULL;
tryToAllocateFoo(&pFoo);
Assuming there is following C code:
struct Foo { int dummy; }
int tryToAllocateFoo(Foo ** dest);
...How to do following in LuaJIT?
Foo * pFoo = NULL;
tryToAllocateFoo(&pFoo);
local ffi = require 'ffi'
ffi.cdef [[
struct Foo { int dummy; };
int tryToAllocateFoo(Foo ** dest);
]]
local theDll = ffi.load(dllName)
local pFoo = ffi.new 'struct Foo *[1]'
local ok = theDll.tryToAllocateFoo(pFoo)
if ok == 0 then -- Assuming it returns 0 on success
print('dummy ==', pFoo[0].dummy)
end
© 2022 - 2024 — McMap. All rights reserved.
[1]
instead of a second*
! Makes sense, but takes some getting used to. – Applaud