Weather Update

Select a location from the dropdown to display the current weather forecast. The program is available in the CVS repository.

Weather Update screenshot

The required libraries in this case are:

require "gtk" require "gtk.http_co" require "lxp" require "gtk.strict"

"lxp" is LuaExpat, the binding to the expat xml parser. The following function is the handler for changes in the dropdown and starts an asynchronous HTTP request to fetch the weather info. The "_co" suffix indicates that a coroutine is used.

function on_location_changed(box) local store = box:get_model() local iter = "TreeIter" box:get_active_iter(iter) local prov = store:get_value(iter, 1, nil) local location = store:get_value(iter, 2, nil) -- load the appropriate provider module on first use if not providers[prov] then providers[prov] = require(prov) end providers[prov]:get_data(location) end

The total code size of this example is about 270 lines, most of it concerned with parsing the response and building the GUI elements to show it.