On Wednesday, 19 March 2014 at 02:21:18 UTC, James Wirth wrote:
When trying to associate an Icallback function to a button in the IUP GUI API using the IupSetCallback function, the D compiler seems to insist on evaluating that callback in order to pass its value rather than passing the function itself.

I get this dmd compiler error (the source is named hitmeiup.d) :

Error: function hitmeiup.hitMeAct (Ihandle_* dmy) is not callable using argument types ()
hitmeiup.d(41): Error: expected 1 function arguments, not 0

for this line calling the IupSetCallback:

        IupSetCallback(btn,"ACTION",hitMeAct);

The callback function was named hitMeAct as follows:

extern(C) {
        int hitMeAct(Ihandle *dmy) {
                sayHit();
                return 0;
        }
}

I have also tried it with hitMeAct being a D function instead of extern(C).

It is as if the call to IupSetCallback is interpreting hitMeAct to be a property function and that the call was meant to be:

        IupSetCallback(btn,"ACTION",hitMeAct());

It there someway to force D to consider the hitMeAct parameter to be passing a function and NOT calling it? I tried prefixing a & - no go.

Would welcome any hints.

Yes I have already looked at the .d files purporting to provide access to IUP.
And a more or less equivalent C program works fine.

Using & to get the function pointer is correct in this case.
You may need to do a cast for the pointer to what c expects. However it will work fine.
The brackets forces it to call it. Don't.

Reply via email to