calling a C++ DLL from LuaJIT -
i know can't use ffi load in c++ dll (only c work), how go doing this? if need use wrapper, how started that?
edit: cannot change dll in way whatsoever.
you can try mangling names manually in ffi cdefs, different compilers use different name mangling schemes, not mention referring functions awkward.
rather manually mangling names in cdef, recommend writing wrapper in c. while tedious, it's not difficult. gist of c side of treats classes opaque structs pass around wrapper functions. see site more details , gotchas, though.
here's sample snippet of wrapper use box2d:
#include <box2d/box2d.h> #ifdef __linux__ #define cexport extern "c" #else #define cexport extern "c" __declspec(dllexport) #endif // /////////////////////////////////////////////////////// // world cexport b2world* b2world_new(b2vec2* gravity) { return new b2world(*gravity); } cexport void b2world_destroy(b2world* world) { delete world; } cexport b2body* b2world_createbody(b2world* world, const b2bodydef* def) { return world->createbody(def); } cexport void b2world_destroybody(b2world* world, b2body* body) { world->destroybody(body); } cexport void b2world_step(b2world* world, float32 timestep, int32 veliters, int32 positers) { world->step(timestep, veliters, positers); } cexport b2body* b2world_getbodylist(b2world* world) { return world->getbodylist(); }
and corresponding cdecl:
typedef struct b2world b2world; b2world* b2world_new(b2vec2*); void b2world_destroy(b2world*); b2body* b2world_createbody(b2world*, const b2bodydef*); void b2world_destroybody(b2world*, b2body* body); void b2world_step(b2world*, float, int32_t, int32_t); b2body* b2world_getbodylist(b2world*);
Comments
Post a Comment