File: objects.html

package info (click to toggle)
lua-gtk 0.9%2B20100528-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,176 kB
  • ctags: 1,934
  • sloc: ansic: 9,571; sh: 373; makefile: 241
file content (56 lines) | stat: -rwxr-xr-x 2,115 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

<p>
A special data type is the <i>object</i>, which is often a widget, i.e. an
area on screen which is part of a GUI, e.g. a label, button etc.
</p>

<p>
In Glib-based libraries, all objects are derived from the base class
<i>GObject</i>.  These are handled specially in following ways:
</p>

<dl>

 <dt>Method Invocation</dt>
 <dd>When you call a method on an object, e.g. win:set_title(), then
 a function name is constructed from the object's type and the method
 name, in this case gtk_window_set_title(). </dd>

 <dt>Reference Counting</dt>
 <dd>GObjects have reference counts, which are generally managed automatically
 by LuaGnome so you don't have to worry about them.  In some corner cases
 you may have to think about it, mostly that you keep a Lua proxy object
 around until the referenced object isn't required anymore.</dd>

 <dt>Additional Methods</dt>
 <dd>Some operations on objects are handled through C macros, which are not
 available - only functions are.  Therefore, a few extra methods are
 defined:
  <ul>
    <li>lg_get_type(): returns the name of the object's class.  It is not
    named <i>get_type()</i>, because this would hide other functions
    by this name, e.g. cairo.surface_get_type().  </li>
  </ul>
 </dd>

 <dt>Data Storage</dt>
 <dd>Each Lua proxy object (a userdata) can store arbitrary key/value pairs
 in its environment, which is a regular Lua table attached to such proxy
 objects.  As long as you keep the proxy object, this data is retained, even
 if this is an argument to a callback - the same proxy object will be
 reused, and retains the data. </dd>

 <dt>Access to structure fields</dt>
 <dd>Any GObject and derived objects have an underlying C structure; all the
 fields can be read and written by simply accessing them just as you would
 for a Lua table.</dd>

 <dt>Type casting</dt>
 <dd>It is possible to cast a type to another by using the function
 <b>gnome.cast</b>, e.g. when you have a GdkEvent e and know by inspecting
 e.type that this is a key event, you can call e = gnome.cast(e, "GdkEventKey")
 to get access to key specific fields.
 </dd>

</dl>