summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2015-06-05 21:49:40 -0400
committerTed Trask <ttrask01@yahoo.com>2015-06-05 21:49:40 -0400
commitbe9beb6bf6d4688043d5f80b75bfb2aa6aa8670a (patch)
treebacddfc92d0c55d68d8e11fc49ae86522da53d78
parentdf5ea29873edff8d54bf94eb5ff494dfd9837d4f (diff)
downloadacf-core-be9beb6bf6d4688043d5f80b75bfb2aa6aa8670a.tar.bz2
acf-core-be9beb6bf6d4688043d5f80b75bfb2aa6aa8670a.tar.xz
Create a metatable for all cfe objects containing print_errtxt function
-rwxr-xr-xlua/mvc.lua29
1 files changed, 29 insertions, 0 deletions
diff --git a/lua/mvc.lua b/lua/mvc.lua
index 17b750e..4ef4eb7 100755
--- a/lua/mvc.lua
+++ b/lua/mvc.lua
@@ -420,6 +420,34 @@ mymodule.exception_handler = function (self, message )
error(message)
end
+-- Create a metatable to be used for all cfe objects
+local cfe_mt = {}
+cfe_mt.__index = cfe_mt
+cfe_mt.print_errtxt = function(self)
+ local errtxt = {}
+ local function get_errtxt(self, name)
+ if self.errtxt then
+ if name then
+ errtxt[#errtxt+1] = name..": "..self.errtxt
+ else
+ errtxt[#errtxt+1] = self.errtxt
+ end
+ end
+ if "group" == self.type or "form" == self.type then
+ if not name then
+ name = ""
+ else
+ name = name.."."
+ end
+ for n,v in pairs(self.value) do
+ get_errtxt(v, name..n)
+ end
+ end
+ end
+ get_errtxt(self)
+ return table.concat(errtxt, "\n")
+end
+
-- create a Configuration Framework Entity (cfe)
-- returns a table with at least "value", "type", and "label"
mymodule.cfe = function ( optiontable )
@@ -430,6 +458,7 @@ mymodule.cfe = function ( optiontable )
for key,value in pairs(optiontable) do
me[key] = value
end
+ setmetatable(me, cfe_mt)
return me
end
_G.cfe = mymodule.cfe