6

假设有以下 C 代码:

struct Foo { int dummy; }
int tryToAllocateFoo(Foo ** dest);

...如何在 LuaJIT 中进行跟踪?

Foo * pFoo = NULL;
tryToAllocateFoo(&pFoo);
4

1 回答 1

11
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
于 2012-12-23T22:01:53.433 回答