How to pass a pointer to LuaJIT ffi to be used as

2019-03-29 07:00发布

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);

标签: lua ffi luajit
1条回答
趁早两清
2楼-- · 2019-03-29 07:43
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
查看更多
登录 后发表回答