lgob 13.09 released

15 Sep 2013

Yesterday I’ve released lgob 13.09, which fixes issues with newer GCC versions on x64 systems.

lgob is a compiler that automatically generates C code to bind GObject-based libraries, like GTK+ and WebKitGTK+, to Lua. It works by parsing GObject-Introspection .gir files and emitting C code. Any library that supports GObjectIntrospection can be made available for Lua by using lgob.

lgob already ships with ready to use modules for popular libraries like GTK+, GDK, gstreamer, pango, cairo (besides not being GObject-based), WebKitGTK+, poppler, vte, GtkSourceView, and others.

Install

lgob depends on Lua 5.1 / luajit (but should be easy to port to Lua 5.2), and the libraries that one wish to use (GTK+, vte, etc).

To build and install all available modules to /usr/local, run (inside of the extracted lgob package):

$ lua5.1 build_all.lua /usr/local

Code samples

There are more than 50 examples in lgob package. lgob-generated bindings uses the same API as the original library, e.g., you can use the original API reference to program in Lua with lgob.

Some code samples are listed below.

Hello GTK+

require('lgob.gtk')

local window = gtk.Window.new(gtk.WINDOW_TOPLEVEL)
window:connect('delete-event', gtk.main_quit)

local button = gtk.Button.new_with_label("Click me")
button:connect('clicked', function() print("clicked") end )

window:add(button)
window:show_all()
gtk.main()

Entry

require('lgob.gtk')

local window = gtk.Window.new(gtk.WINDOW_TOPLEVEL)
window:connect('delete-event', gtk.main_quit)
window:set('title', 'Entry demo', 'window-position', gtk.WIN_POS_CENTER, 'default-width', 200)

local entry = gtk.Entry.new()
entry:set('primary-icon-stock'  , 'gtk-find')
entry:set('secondary-icon-stock', 'gtk-clear')

entry:connect('icon-press', function(ud, pos, event)
    if pos == gtk.ENTRY_ICON_PRIMARY then
        print('searching for ' .. entry:get('text') )
    else
        entry:set('text', '')
    end
end)

window:add(entry)
window:show_all()

gtk.main()

Note: lgob is know to work on MS-Windows too, but there are no official builds. Last time I’ve cross-compiled it with MinGW by using the windows GTK+ build from OpenSuse build service.