Scuri, thanks for the answer. My initial puzzling was how the the
callbacks functions get their parameters assigned.
I'm no professional programmer but have several years of C experience.
However, there is a certain level of pointers wizardry at which I start
to "patinar".
Anyway, I do it exactly as you said. See this little example that
results from adapting the the examples/menu.c
It's almost a one-to-one conversion.
Joaquim
function menu()
IupOpen() #Initializes IUP
item_open = IupItem ("Open", "");
IupSetAttribute(item_open, "KEY", "O");
item_save = IupItem ("Save", "");
IupSetAttribute(item_save, "KEY", "S");
item_undo = IupItem ("Undo", "");
IupSetAttribute(item_undo, "KEY", "U");
IupSetAttribute(item_undo, "ACTIVE", "NO");
item_exit = IupItem ("Exit", "");
IupSetAttribute(item_exit, "KEY", "x");
IupSetCallback(item_exit, "ACTION", cfunction(exit_cb, Cint,
(Ptr{Ihandle},)))
file_menu = IupMenu(item_open,
item_save,
IupSeparator(),
item_undo,
item_exit)
sub1_menu = IupSubmenu("File", file_menu);
thismenu = IupMenu(sub1_menu)
IupSetHandle("mymenu", thismenu)
dlg = IupDialog(IupCanvas(""))
IupSetAttribute(dlg, "MENU", "mymenu")
IupSetAttribute(dlg, "TITLE", "IupMenu")
IupShow(dlg)
IupMainLoop() # Initializes IUP main loop
IupClose() # And close it when ready
end
function exit_cb(h::Ptr{Ihandle})
return convert(Cint, IUP_CLOSE)
end
> Ok. Good news anyway.
>
> The callback is called from inside IUP with all the parameters. But
> in C we can omit some of the parameters in the callback
> implementation. That's why the difference on the example.
>
> In language binding implementation we recommend you to implement a C
> callback that actually calls a function in the language
> implementation, in your case a Julia function.
>
> So when inside a Julia script you set a callback to a Julia function,
> this will call a C function that will set that C callback. This
> implies that from that generic C callback you must be able to tell
> which Julia function to call.
>
> Well all this is heavily dependent on the language but that's an
> overview on how to do it.
>
> Best,
> Scuri
>
> On Wed, Jun 11, 2014 at 10:49 PM, Joaquim Luis<[email protected]> wrote:
>> Ghrrr, excuse me for the noise. I had not read correctly the docs of
>> Julia's "cfunction" function. I don't need to know the parameters in
>> advance, only their types and that I know. So I got it working (at least
>> for a simple example).
>>
>> Joaquim
>>
>>> Hi,
>>>
>>> First time here and new to IUP but unconscious enough to attack a
>>> challenging problem.
>>>
>>> I am playing around trying to port bits of IUP to Julia and already made
>>> it work for a couple of examples of the examples section, but got stuck
>>> in the callbacks mystery.
>>>
>>> Take the button.c example as an example
>>>
>>> It has a line that sets the callback
>>>
>>> IupSetCallback( btn_image, "ACTION", (Icallback) btn_image_button_cb
>>> );
>>>
>>> and the beginning of the CB reads like
>>>
>>> int btn_image_button_cb( Ihandle *self, int b, int e ) {
>>> /* If the left button changed its state... */
>>> if( b == IUP_BUTTON1 ) {
>>> ...
>>>
>>> Now, the big mystery to me is where does the btn_image_button_cb()
>>> function gets its arguments from? Note that in the IupSetCallback() call
>>> there are no arguments transmitted but they managed to find their way to
>>> btn_image_button_cb(). And why only those three and not the all
>>> collection mentioned in the docs?
>>>
>>> Understanding this and finding how to set the args is crucial for the
>>> Julia port because there one has to declare the arguments list as well
>>> as their types.
>>> For example as in (this is a Julia line)
>>>
>>> IupSetCallback (btn_exit, "ACTION", cfunction(btn_exit_cb, Int, (),))
>>>
>>> which works because btn_exit_cb() can be made to work without any input
>>> arguments.
>>>
>>> Thanks for any help
>>>
>>> Joaquim
>>>
>>> ------------------------------------------------------------------------------
>>> HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
>>> Find What Matters Most in Your Big Data with HPCC Systems
>>> Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
>>> Leverages Graph Analysis for Fast Processing& Easy Data Exploration
>>> http://p.sf.net/sfu/hpccsystems
>>> _______________________________________________
>>> Iup-users mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/iup-users
>>>
>>
>> ------------------------------------------------------------------------------
>> HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
>> Find What Matters Most in Your Big Data with HPCC Systems
>> Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
>> Leverages Graph Analysis for Fast Processing& Easy Data Exploration
>> http://p.sf.net/sfu/hpccsystems
>> _______________________________________________
>> Iup-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/iup-users
>>
> ------------------------------------------------------------------------------
> HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
> Find What Matters Most in Your Big Data with HPCC Systems
> Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
> Leverages Graph Analysis for Fast Processing& Easy Data Exploration
> http://p.sf.net/sfu/hpccsystems
> _______________________________________________
> Iup-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/iup-users
>
------------------------------------------------------------------------------
HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
Find What Matters Most in Your Big Data with HPCC Systems
Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
Leverages Graph Analysis for Fast Processing & Easy Data Exploration
http://p.sf.net/sfu/hpccsystems
_______________________________________________
Iup-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/iup-users