3
These are some hints how to avoid common problems in your applications.
8
<dt>Disconnect handlers</dt><dd>Objects cannot be freed when there are
9
still signal handlers connected. On widgets, you can call the method
10
<tt>destroy()</tt>, which disconnects all handlers, destroys child
11
widgets and removes itself from parents. For non-widgets, you can
12
remember the handler_ids returned from the <tt>connect</tt> call like this:
15
handler_id = obj:connect('signal-name', signal_handler)
16
obj:disconnect(handler_id)
20
<dt>Retrieving values from pointer arguments</dt>
21
<dd>Functions sometimes expect a pointer to a memory location where they
22
can place a return value. If you specify <tt>nil</tt> for that argument, a
23
NULL pointer is given to the function, which normally means that the return
24
value should not be stored, rather discarded. <br/>
26
For <tt>int*</tt> and similar types, you should simply give a value to
27
initialize the memory location with; the function can then overwrite it and
28
it will be returned to the caller. <br/>
30
For <i>double pointer to enum</i> arguments you should specify
31
<b>gnome.NIL</b> instead of nil, like in the following example:
34
-- call gchar* g_file_read_link(const gchar*, GError**)
35
s, err = glib.file_read_link(path, gnome.NIL)
43
<dt>Wrong data type for vararg</dt>
44
<dd>When converting Lua values to call a library function with variable
45
arguments, sometimes the wrong data type is used. For example, consider
48
glib.printf("%f\\n", 20)
50
In this case. an integer is given to printf, which actually expects a double.
51
To avoid this, use a <b>Boxed Value</b> with a type cast, like this:
54
glib.printf("%f\\n", gnome.box(20, "double"))