LuaJIT FFI should not be mixed with classic C/API. While there are mechanisms to convert a const char*
pointer to Lua string (ffi.string
), there is no way to convert an FFI struct to Lua userdata.
FFI functions have no knowledge of a lua_State, which is needed to create userdata on the C side.
I don't know how large your C/API binding base is at the moment, but one solution would be to rewrite your C/API functions to FFI, if you're set on using FFI. You can do it gradually, making sure that there is a clear line between FFI and C/API.