Difference between revisions of "Eve definitions in Lua"

From Adobe Open Source Wiki
Jump to: navigation, search
(Eve definitions in Lua)
 
(duplicate title removed)
 
Line 1: Line 1:
== Eve definitions in Lua ==
 
 
 
Often many dialogs in an application have very similar Eve definitions. For example, all of the "Properties" dialogs on Windows contain a tab group and "OK/Cancel/Apply" buttons. It would be nice to be able to define functions that return commonly used combinations of widgets.
 
Often many dialogs in an application have very similar Eve definitions. For example, all of the "Properties" dialogs on Windows contain a tab group and "OK/Cancel/Apply" buttons. It would be nice to be able to define functions that return commonly used combinations of widgets.
  

Latest revision as of 23:14, 28 September 2006

Often many dialogs in an application have very similar Eve definitions. For example, all of the "Properties" dialogs on Windows contain a tab group and "OK/Cancel/Apply" buttons. It would be nice to be able to define functions that return commonly used combinations of widgets.

One solution to this problem is to write the Eve definitions in an embeddable language such as Lua.

My current thinking is that a datastructure would be built in Lua that defines all of the views, and that there would be a function exposed that would take this datastructure and build a UI from it. So an Eve definition might look like this:

view = dialog{ name = "Test" }
{
 row{ horizontal = "align_fill", vertical = "align_fill" }
 {
   static_text{ name = "This is a test." },
   button{ name = "Click me", action: cancel }
 }
}
--
-- Now build it.
--
asl_factory(view)

The various view functions (dialog, row, static_text, button, etc) can be defined like this:

function leaf_factory(name)
	return function(params)
		local t = {}
		t.name = name;
		t.params = params;
		return t;
	end
end

function container_factory(name)
	return function(params)
		return function(children)
			local t = {}
			t.name = name;
			t.params = params;
			t.children = children;
			return t;
		end
	end
end

local dialog = container_factory("dialog")
local row = container_factory("row")
local column = container_factory("column")
local static_text = leaf_factory("static_text")
local button = leaf_factory("button")