Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add support for GLib.Timer

Solves #39
  • Loading branch information...
commit 735c95623433fa736f182c9b0d9b05b4e7bdb25b 1 parent 6f657f1
@pavouk authored
View
1  lgi/init.lua
@@ -64,6 +64,7 @@ repo.GLib._precondition = {}
for _, name in pairs { 'Variant', 'VariantType', 'VariantBuilder' } do
repo.GLib._precondition[name] = 'GLib-Variant'
end
+repo.GLib._precondition.Timer = 'GLib-Timer'
-- Access to module proxies the whole repo, so that lgi.'namespace'
-- notation works.
View
33 lgi/override/GLib-Timer.lua
@@ -0,0 +1,33 @@
+-------------------------------------------------------------------------------
+--
+-- LGI GLib Timer support implementation.
+--
+-- Copyright (c) 2013 Pavel Holejsovsky
+-- Licensed under the MIT license:
+-- http://www.opensource.org/licenses/mit-license.php
+--
+-------------------------------------------------------------------------------
+
+local pairs = pairs
+
+local lgi = require 'lgi'
+local core = require 'lgi.core'
+local record = require 'lgi.record'
+local ffi = require 'lgi.ffi'
+local ti = ffi.types
+
+local Timer = lgi.GLib.Timer:_resolve(true)
+
+local module = core.gi.GLib.resolve
+for name, def in pairs {
+ new = { ret = { Timer, xfer = true } },
+ elapsed = { ret = ti.double, { Timer }, { ti.ulong, dir = 'out' } },
+} do
+ local _ = Timer[name]
+ def.addr = module['g_timer_' .. name]
+ Timer._method[name] = core.callable.new(def)
+end
+
+Timer._free = core.gi.GLib.Timer.methods.destroy
+Timer._method.destroy = nil
+Timer._new = function(_, ...) return Timer.new(...) end
View
46 tests/glib.lua
@@ -0,0 +1,46 @@
+--[[--------------------------------------------------------------------------
+
+ LGI testsuite, GLib test suite.
+
+ Copyright (c) 2013 Pavel Holejsovsky
+ Licensed under the MIT license:
+ http://www.opensource.org/licenses/mit-license.php
+
+--]]--------------------------------------------------------------------------
+
+local lgi = require 'lgi'
+
+local check = testsuite.check
+
+-- Basic GLib testing
+local glib = testsuite.group.new('glib')
+
+function glib.timer()
+ local Timer = lgi.GLib.Timer
+ check(Timer.new)
+ check(Timer.start)
+ check(Timer.stop)
+ check(Timer.continue)
+ check(Timer.elapsed)
+ check(Timer.reset)
+ check(not Timer.destroy)
+
+ local timer = Timer()
+ check(Timer:is_type_of(timer))
+ timer = Timer.new()
+ check(Timer:is_type_of(timer))
+
+ local el1, ms1 = timer:elapsed()
+ check(type(el1) == 'number')
+ check(type(ms1) == 'number')
+
+ for i = 1, 1000000 do end
+
+ local el2, ms2 = timer:elapsed()
+ check(el1 < el2)
+
+ timer:stop()
+ el2 = timer:elapsed()
+ for i = 1, 1000000 do end
+ check(timer:elapsed() == el2)
+end
View
1  tests/test.lua
@@ -110,6 +110,7 @@ for _, sourcefile in ipairs {
'corocbk.lua',
'record.lua',
'gobject.lua',
+ 'glib.lua',
'variant.lua',
'gtk.lua',
'cairo.lua',
Please sign in to comment.
Something went wrong with that request. Please try again.