Here is the code. The aim is to print messages. In PrintC, I would like to get e...but arrives as cdata. How can I unpack that or circumvent that?
extern "C"
{
static int PrintC ( lua_State *L )
{
// does not work cdata
//executor* e = ( executor* ) luaL_checkudata(L, 1, "cdata"); does n
//luaL_checkudata(L, 1, "void *");
if ( e->writelog )
{
int no = lua_gettop ( L ) ;
for ( int i = 2; i <= no; i++ )
{
cout << lua_tostring (L,i);
}
}
return 1;
}
}
// initialised as
lua_pushcfunction ( L, PrintC );
lua_setglobal ( L, "PrintC" );
lua_pushinteger ( L, ( long ) this ); // this is in a class executor
lua_setglobal ( L, "p" );
p= ffi.cast("void *",p)
function Print()
return PrintC(p)
end
You can't. The Lua C API and the LuaJIT FFI are deliberately separated and cannot interact.
Rewrite PrintC
in Lua using the FFI, or write Lua C API bindings to the library you're using p
with. I.e. Use one or the other.