Is it possible to use functions from c++ namespaces with luajit ffi?
I've got a lot of c++ code which contains a lot of functions and classes in namespaces (boost, for example).
Now I'm trying to embed LuaJiT2 as script engine, but I cannot find anything about calling functions and using other st开发者_如何学Cuff from namespaces. So, Is it possible to pass the functions from c++ namespaces to LuaJIT with the FFI?You may use the standard Lua API to expose namespace-scope functions, as well as class static functions, to Lua. This is done exactly as you would with the regular Lua interpreter, since LuaJIT is drop-in compatible with it.
But you can't use FFI, because FFI is based on a C-based parsing of the header files. And you're using C++ syntax. FFI is not the only way to use LuaJIT; it's just one that is based on C.
Any of the C++-specific binding APIs that use Lua (Luabind, SWIG, etc) should work just fine with LuaJIT as well.
It is possible to use different name mangling other than C. The reason why its not "common" is because the C++ name mangling is very compiler/platform specific: http://lua-users.org/lists/lua-l/2011-07/msg00502.html
So this sort of declaration is valid:
ffi.cdef[[
void Test1_Method1(void) asm("_ZN5Test17Method1Ev");
]]
And you can then call Test1_Method1. Mike Pall has done an amazing job with luajit. So many great features.
精彩评论