Chipmunk and LuaJit FFI
Posted: Fri Dec 16, 2011 11:36 pm
I'm trying to get chipmunk working thru the LuaJit FFI, but running into problems because many chipmunk functions (cpf* and cpv*) are declared static inline, which the LuaJit FFI can't handle. Is there some way to build chipmunk with the inline functions in the actual .so?
I'm just going to go ahead and patch the source, unless there is an easy way to do this already.
EDIT: oops, i just found chipmunk_ffi.h. I'll probably figure it out eventually, but just in case, how do I use it? I'm guessing recompile chipmunk with `-D CHIPMUNK_FFI`, and then `#define CHIPMUNK_FFI` to get the declarations? The functions will be prefixed with an underscore, right?
EDIT2: ok I put `-DCHIPMUNK_FFI` in the cflags, but that caused error messages:
EDIT3: Ok so the problem was that chipmunk_ffi.h had something about IsSensor, when the actual function was just Sensor, so I fxed that and it compiled.
Now how do I get the include (#include "chipmunk/chipmunk.h") to have the correct declarations?
EDIT4: Neato! it worked:
prints 2, as expected. Still have to do something about the header file declarations so I don't have to declare manually like this.
I'm just going to go ahead and patch the source, unless there is an easy way to do this already.
EDIT: oops, i just found chipmunk_ffi.h. I'll probably figure it out eventually, but just in case, how do I use it? I'm guessing recompile chipmunk with `-D CHIPMUNK_FFI`, and then `#define CHIPMUNK_FFI` to get the declarations? The functions will be prefixed with an underscore, right?
EDIT2: ok I put `-DCHIPMUNK_FFI` in the cflags, but that caused error messages:
Code: Select all
[ 12%] Building C object src/CMakeFiles/chipmunk.dir/chipmunk.c.o
In file included from /home/eee/builds/Chipmunk-6.0.1/src/chipmunk.c:170:0:
/home/eee/builds/Chipmunk-6.0.1/include/chipmunk/chipmunk_ffi.h:80:1: error: ‘cpShapeGetIsSensor’ undeclared here (not in a function)
/home/eee/builds/Chipmunk-6.0.1/include/chipmunk/chipmunk_ffi.h:80:1: error: ‘cpShapeSetIsSensor’ undeclared here (not in a function)
make[2]: *** [src/CMakeFiles/chipmunk.dir/chipmunk.c.o] Error 1
make[1]: *** [src/CMakeFiles/chipmunk.dir/all] Error 2
make: *** [all] Error 2
Now how do I get the include (#include "chipmunk/chipmunk.h") to have the correct declarations?
EDIT4: Neato! it worked:
Code: Select all
ffi.cdef[[
double (*_cpfclamp)(double f, double min, double max);
]]
cp=ffi.load 'chipmunk'
print(cp._cpfclamp(5, -1, 2))