0

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

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Why are they separated? It would be nice to have a way between them

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.