lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Steven Berry wrote:
> My current approach is to run my binding generator before compilation and
> generate a cpp + lua binding file. 
> I use clang to visit each method and output the corresponding wrapper
> function.

If you feel a bit adventurous, then you can directly bind to the
C++ methods by using the mangled symbol names with the symbol
renaming feature:

ffi.cdef[[
void Test1_Method1(void) asm("_ZN5Test17Method1Ev");
]]

The name mangling is very compiler/OS/CPU specific, though. And a
few platforms use different calling conventions for methods, which
is not yet implemented.

>    C = ffi.C

local C = ffi.C

>    local Test1_index = {Method1 = function(__this, text)
> C.Test1_Method1(__this, text) end }

You don't need the indirection with a Lua function:

local Test1_index = { Method1 = C.Test1_Method1 }

[Whenever I get around to parse a very restricted subset of C++,
most of that will be superfluous. But don't hold your breath.]

--Mike