How to specify user data before the callback parameter in Vala?

I have a C API that looks like this:

typedef void (*cprcen_channel_callback) (CPRC_abuf *abuf, void *user_data);
int CPRCEN_engine_set_callback(CPRCEN_engine *eng, CPRCEN_channel_handle chan,
    void *userdata, cprcen_channel_callback callback);

As you can see, the function CPRCEN_engine_set_callbacktakes user data before the callback, whereas by default Vala expects this to happen. I know about attribute CCodeattribute delegate_target_pos, but no matter what position I specify, the value userdatagets as the first argument instead of the third in the generated function call. I just can't bow my head around the Vala parameter positioning logic.

Here is how I would like the binding to eventually look:

[CCode(cname = "cprcen_channel_callback", has_target = true)]
public delegate void ChannelCallback(AudioBuffer abuf);

[Compact]
[CCode(cname = "CPRCEN_engine")]
public class Engine {
    [CCode(cname = "CPRCEN_engine_set_callback")]
    public int set_channel_callback(ChannelHandle chan, ChannelCallback callback);
}

How do I do this job?

+4
source share
1

1.5 :

[CCode(cname = "CPRCEN_engine_set_callback")]
public int set_channel_callback(ChannelHandle chan, [CCode (delegate_target_pos = 1.5)] ChannelCallback callback);

. 1.5 (chan) ( ). , 2.5 ..

, , . - 0 1 (, 0,5) CCode _, - , 1, 0,5 (, 0,9).

+4

All Articles