Re: [Vala] Properly wrapping callbacks



On Mon, 2009-01-26 at 20:33 +0100, Michael 'Mickey' Lauer wrote:
Hi,

I think that the delegate should be static:

[CCode (instance_pos = 0)]
public static delegate int AtCommandCallback( string cmd );

Thanks, still the same error though.


Yes there are some other errors there.

See the following simple example adapted from your code, it complies
fine with vala 0.5.6.

(I should use some short namespace but I haven't just because I'm little
lazy ;) )


Regards,

Andrea

using GLib;

public class Multiplexer : Object
{
        Context ctx;

        public static int at_command_cb (Context ctx, string command)
        {
                Multiplexer m = (Multiplexer) ctx.user_data;
                debug( "CB: atCommand %s", (string)command );
                return 1;
        }

        public Multiplexer( bool advanced, int framesize, string device, int
portspeed )
        {
                debug( "Multiplexer created for mode %s, framesize %d, device %s %d",
advanced? "advanced":"basic", framesize, device, portspeed );
                ctx = new Context();
                ctx.at_command = at_command_cb;
        }
}

====================== Vapi file ====================
public class Context
{
        public void* user_data;
        public AtCommandCallback at_command;
}

[CCode (instance_pos = 0)]
public static delegate int AtCommandCallback (Context ctx, string cmd);




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