luajit ffi - 如何在ffi/luajit中编程指向c函数的指针

对于ffi,我是个新手,需要帮助在lua中通过ffi将这个c/c++声明编码。

从代码中阅读,我有一个函数,其中一个传递参数是一个指向函数的指针。我可能完全错了,我说过我是一个新手!

这是typedef:

ffi.cdef[[typedef void (* XPLMReceiveMonitorBoundsGlobal_f)(
                               int                  inMonitorIndex,
                               int                  inLeftBx,
                               int                  inTopBx,
                               int                  inRightBx,
                               int                  inBottomBx,
                               void *               inRefcon);]]

这是函数定义:

ffi.cdef("void XPLMGetAllMonitorBoundsGlobal(XPLMReceiveMonitorBoundsGlobal_f inMonitorBoundsCallback, void * inRefcon)")

我已经尝试猜测如何使用我的想象力在lua中编写这个代码大约4个小时,例如:

XPLM.XPLMGetAllMonitorBoundsOS(XPLMReceiveMonitorBoundsOS_f(monindex, leftpx, toppx, rightpx, bottompx, nil), nil)

XPLM.XPLMGetAllMonitorBoundsOS(), nil)

我想到的任何事都没有起作用,谷歌搜索和大量阅读也没有让我更接近答案。

编码是为了在XPlane飞行模拟器中的lua应用程序,最接近错误的东西是:

"attempt to call global 'XPLMReceiveMonitorBoundsOS_f' (a nil value)"

也许我必须通过ffi.new(),ffi.cast()等定义一些东西,但我肯定没有想出答案。

非常感谢你的帮助。

Ian

点赞