Glade4lua: Design with Glade, implement in Lua

WARNING: I am no longer working on this. See this material as a proof of concept, but not as a usable product.

Glade4lua is a Lua script which reads a Glade GUI design (XML file), and generates a Lua function than constructs the whole widget tree. The generated code uses Lgob, an elegant an compact Lua binding for GTK+, GDK, Pango and more.


For now, Glade4lua is just a 'proof of concept' project. I'll extend it as time allows… I intend to use it to build simple applications for my Iliad (E-book). A first example is MiniPad: a simple text editor (see

  • 05 okt 2009: initial version
  • 14 okt 2009: added hash with all widgets, optimised (shorter) output
  • 28 okt 2009: allow or more top windows, switch to 'libglade' format, better attribute handling


(including the described example and the generated code) can be downloaded here: glade4lua.tgz. I keep my files in svn at

Glade4lua depends on Lgob.


1: Design a GUI

Design with glade-3 (choose the Libglade mode, this works best with all GTK versions), save it as 'example': this results in an XML file ''

Note for Iliad: The Iliad has a very old version of GTK: 2.6. Select the GTK 2.8 option, it's the oldest version supported by Glade-3.

2: Convert to Lua

./glade4lua >example.lua

3: Write an application


#!/usr/bin/env lua
require("lgob.gtk")             -- Binding for GTK+
require("lgob.gdk")             -- Binding for GDK
require 'print_r'               -- debug 
builder = require 'example'     -- This is the generated GUI implementation
-- Callback table: these function are called by GUI events
local CB_mt = {}
function CB_mt.__index(t, key)
  return function(a,b,c)
    print ("undefined callback: "..key, a, b, c)
CB = {
  quit = gtk.main_quit,
  hello = function()
    print('Hello World!')
setmetatable(CB, CB_mt)
local tree = builder(CB)         -- Contruct the GUI

4: Run it!


5: Iterate

Goto step 1 or 3 until you are satisfied 8-)


I am no longer working on this. See this material as a proof of concept, but not as a usable product.**

Last modified: 2010/11/30 07:41 Mijn Fijne Site hosting en design