~nimu-zh3/+junk/lua-gtk

« back to all changes in this revision

Viewing changes to examples/maincontext.lua

  • 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
#! /usr/bin/env lua
 
2
-- vim:sw=4:sts=4
 
3
--
 
4
-- Demonstrate how to manually run the main loop
 
5
--
 
6
 
 
7
require "gtk"
 
8
-- gnome.set_debug_flags("memory", "trace")
 
9
 
 
10
function my_main()
 
11
 
 
12
    local ctx, ok, cnt
 
13
 
 
14
    ctx = glib.main_context_default()
 
15
    ok = glib.main_context_acquire(ctx)
 
16
    assert(ok)
 
17
 
 
18
    cnt = 5
 
19
    local pfd = glib.new_array("PollFD", cnt)
 
20
    local n, timeout = glib.main_context_query(ctx, 1000, 0, pfd, cnt)
 
21
    glib.main_context_release(ctx)
 
22
 
 
23
    print("timeout is", timeout)
 
24
    for i = 1, n do
 
25
        print(string.format("File descriptor #%d is %d", i, pfd[i].fd))
 
26
    end
 
27
 
 
28
end
 
29
 
 
30
-- add another file descriptor, so that the _query function will return
 
31
-- more than one, just to demonstrate the array-of-objects feature.
 
32
function add_a_source()
 
33
    local ctx = glib.main_context_default()
 
34
    local pfd = glib.new "PollFD"
 
35
    pfd.fd = 90
 
36
    pfd.events = 3
 
37
    glib.main_context_add_poll(ctx, pfd, 10)
 
38
end
 
39
 
 
40
add_a_source()
 
41
my_main()
 
42