-- -- zone_builder.scr -- -- @author Matthew M. Burke -- @version 1.0 -- -- Defines a "language" for defining zones. -- Note how in the call to the zone function we take advantage of an interesting -- bit of Lua syntax: if the sole argument to a function is a (literal) table or string, -- then the parenthesis for the function call are optional. -- -- -- What sort of error-proofing can you think to add to this function? -- How can we modify this function to handle _lots_ of zone settings without -- having it become long and tedious? function zone(zone_data) zdex = add("zone", zone_data.name) if zone_data.thermal then set("zone.thermal", zdex, zone_data.thermal) end if zone_data.color then set("zone.color", zdex, zone_data.color) end if zone_data.system then set("zone.system", zdex, zone_data.system) end if zone_data.activity then set("zone.activity", zdex, zone_data.activity) end return zdex end -- Note we can "hide" the above function definition (and others) -- by sticking them in a different file and then just including the file. -- this allows us to have our "data definition" files look quite clean and simple. -- cmd("model.new") zone { name = "My Zone", thermal = 1, system = "heating", } zone { name = "Another Zone", color = "0xFF88AA" } set("app.page", 1) set("app.panel", 1)