~ubuntu-branches/ubuntu/natty/lua-gtk/natty

« back to all changes in this revision

Viewing changes to doc/en/pitfalls.html

  • Committer: Bazaar Package Importer
  • Author(s): Enrico Tassi
  • Date: 2009-05-17 18:16:21 UTC
  • mfrom: (1.2.1 upstream) (4.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090517181621-9kmdd82nxg54jsio
* new upstream snapshot comprising many more GNOME libraries:
    Gtk, GDK, GLib, Pango, Atk, Libxml2, Cairo, Clutter, Gtkhtml, 
    GtkSourceView, Gio, Gtkspell and GConf. 
* new upstream release includes a new configure script written in Lua,
  no more bashisms there (Closes: #507205)
* renamed binary packages to liblua5.1-gnome-*
* updated standards-version to 3.8.1, no changes needed
* patch to load .so.* version of libraries and not .so (that was requiring
  -dev packages) (Closes: #522087)
* removed redundant Architecture line from the source stanza of control
  (Closes: #498120)
* updated copyright file, Wolfgang Oertl holds it for 2009 too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
<p>
 
3
These are some hints how to avoid common problems in your applications.
 
4
</p>
 
5
 
 
6
<dl>
 
7
 
 
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:
 
13
 
 
14
<%= inline_code [[
 
15
handler_id = obj:connect('signal-name', signal_handler)
 
16
obj:disconnect(handler_id)
 
17
]] %>
 
18
  </dd>
 
19
 
 
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/>
 
25
 
 
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/>
 
29
 
 
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:
 
32
 
 
33
<%= inline_code [[
 
34
-- call gchar* g_file_read_link(const gchar*, GError**)
 
35
s, err = glib.file_read_link(path, gnome.NIL)
 
36
if err then
 
37
    error(err.message)
 
38
end
 
39
]] %>
 
40
  </dd>
 
41
 
 
42
 
 
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
 
46
 this:
 
47
<%= inline_code [[
 
48
glib.printf("%f\\n", 20)
 
49
]] %>
 
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:
 
52
 
 
53
<%= inline_code [[
 
54
glib.printf("%f\\n", gnome.box(20, "double"))
 
55
]] %>
 
56
 </dd>
 
57
 
 
58
 
 
59
</dl>
 
60