打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
lua

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);
asked Dec 23 '12 at 14:07
Alexander Gladysh
8,4661049101

add comment

1 Answer

up vote 4 down vote accepted
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
answered Dec 23 '12 at 22:01
finnw
22.6k564130

1  
Aha! You have to use [1] instead of a second *! Makes sense, but takes some getting used to. –  Alexander Gladysh Dec 24 '12 at 3:59
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
luajit FFI LUA脚本中怎样调用C自己定义的函数
C/C++中如何使用Luajit脚本
Lua、Luajit、Python、Node.js和Java性能测试对比
Dummy
来总结一下在VC中调用COM组件的方法
技术的“体位”
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服