HTTP Request

This program uses the Glade library to build a GUI from an XML file that has been created using glade-3. The "Start" button starts retrieving the URL; the response body is shown in the textarea upon completion.

Request2 Screenshot

The function to build the GUI is shown below. As you can see, it derives the name of the glade file from the name of the Lua file (including the path). Then, The Glade library is used to read and parse the XML file into an internal representation, from which the widget tree starting at "window1" is created.

require "gtk" require "gtk.glade" function build_gui() local fname, builder, rc, err, sw fname = arg[1] or string.gsub(arg[0], "%.lua", ".ui") builder = gtk.builder_new() rc, err = builder:add_from_file(fname, nil) if rc == 0 then error(err.message) end builder:connect_signals_full(_G) -- statusbar statusbar = builder:get_object "statusbar1" statusbar_ctx = statusbar:get_context_id("progress") statusbar:push(statusbar_ctx, "idle") -- result display sw = builder:get_object "scrolledwindow1" view = output:create() sw:add(view) view:show() end