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

时间:2018-10-27 13:31:30

标签: c lua ffi luajit

对于ffi来说,这是一个新手,寻求帮助,以通过ffi将这个c / c ++声明编码为lua。

在阅读代码的方式中,我有一个函数,该函数具有一个指向函数的指针作为传递的参数之一。我可能完全错了,我确实说我是新手!

这是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()等来定义一些东西,无论如何我当然都没有想出答案。

任何帮助都将不胜感激。

伊恩

0 个答案:

没有答案