Re: ffi and inline functions

  • From: Fjölnir Ásgeirsson <fjolnir@xxxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 14 May 2012 13:59:06 +0900

You'll have to create a library that defines a function pointer to them.
So if your inlined function is: static __inline__ int foo(double bar);
Then this will create a non-inlined copy of that function that you can access 
from luajit:
int(*_foo)(double) = foo;

ffi.cdef[[
int(*_foo)(double);
]]
ffi.C._foo(123)

I use this macro(I use gcc, so I don't know if it'll work in VC++ or not) to 
make the process nicer:
#define EXPOSE(fun) __typeof__(fun) *_##fun = fun

– Fjölnir

On May 14, 2012, at 1:52 PM, Kaj Eijlers wrote:

> Hi group,
> 
> I am (also) trying to wrap some DirectX stuff and ran into a bit of a snatch.
> 
> I am playing with a module that defines the ffi for d3dx9math, and I want to 
> define some inline functions.
> The lua file has the ffi.cdef for the functions in the dll and ends with 
> return ffi.load 'd3dx9_xx.dll'
> That works.
> 
> However, some functions (like D3DXMatrixIdentity) are defined inline. For 
> consistency I'd want them to be prefixed with the same local as I use for the 
> dll (as in, my main says 'local d3d9math = require 'd3d9math', now I want 
> those inline functions to be associated to the metatable that drives the 
> object, but I didn't succeed, I can't set a metatable on d3d9math).
> 
> Does anyone have a pointer (or a reference ;o) ) on how to accomplish this?
> 
> I found it hard to tell whether to send this to the lua or luajit list, since 
> metatables are obviously lua, but ffi is not so much....
> 
> Thanks,
> Kaj

Other related posts: