Re: [Vala] Setting up a timer with callback event
- From: Frederik <scumm_fredo gmx net>
- To: vala-list <vala-list gnome org>
- Subject: Re: [Vala] Setting up a timer with callback event
- Date: Thu, 20 Aug 2009 18:28:38 +0200
George Farris wrote:
Just curious, I'm new to vala, what, in your example, is the purpose of
this line?
//This should activate the timer.
-----> [CCode (instance_pos = -1)]
public void on_btnActivate_clicked (Button source) {
timerID = Timeout.add (1000, on_timer_event);
}
"instance_pos = -1" means that the function expects the instance ('this'
in Vala) as last argument in C code. Usually the instance is passed as
first argument, for example:
void gtk_button_set_label (GtkButton *button, const gchar *label);
^^^^^^ instance
But for callbacks it's passed as last argument in C code, usually named
'user_data':
void on_button_clicked (GtkWidget *button, gpointer user_data);
^^^^^^ sender ^^^^^^^^^ instance
Vala generates the right wrappers for functions that get connected to a
signal somewhere. But Vala can't recognize functions that are meant to
be connected automatically by GtkBuilder because they don't get
connected anywhere in the source code. That's why you must use [CCode
instance_pos = -1] in this case.
Maybe there should be a less confusing alias like [AutoConnect] for this
attribute.
Best Regards,
Frederik
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]