[asterisk-commits] mnicholson: branch mnicholson/asttest r193348 - in /team/mnicholson/asttest/a...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 8 13:46:58 CDT 2009


Author: mnicholson
Date: Fri May  8 13:46:54 2009
New Revision: 193348

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=193348
Log:
fixed indexing of the asterisk, config, and conf_section objects, also renamed
the :write() functions of those objects to avoid conflicting with data members
named "write"

Modified:
    team/mnicholson/asttest/asttest/lua/astlib.lua
    team/mnicholson/asttest/asttest/self-tests/astlib_configs/test.lua

Modified: team/mnicholson/asttest/asttest/lua/astlib.lua
URL: http://svn.asterisk.org/svn-view/asterisk/team/mnicholson/asttest/asttest/lua/astlib.lua?view=diff&rev=193348&r1=193347&r2=193348
==============================================================================
--- team/mnicholson/asttest/asttest/lua/astlib.lua (original)
+++ team/mnicholson/asttest/asttest/lua/astlib.lua Fri May  8 13:46:54 2009
@@ -33,7 +33,6 @@
 	}
 
 	setmetatable(a, self)
-	self.__index = self
 	return a
 end
 
@@ -60,8 +59,12 @@
 	end
 end
 
-function asterisk:__index(conffile_name)
-	return self.configs[conffile_name]
+function asterisk:__index(key)
+	if self.configs[key] then
+		return self.configs[key]
+	end
+
+	return asterisk[key]
 end
 
 function asterisk:new_config(name)
@@ -72,7 +75,7 @@
 
 function asterisk:write_configs()
 	for _, conf in pairs(self.configs) do
-		conf:write()
+		conf:write_config()
 	end
 end
 
@@ -128,7 +131,6 @@
 		section_index = {},
 	}
 	setmetatable(ac, self)
-	self.__index = self
 	return ac
 end
 
@@ -152,11 +154,14 @@
 	return s
 end
 
-function config:__index(section_name)
-	return self.sections[self.section_index[section_name]]
-end
-
-function config:write(filename)
+function config:__index(key)
+	local s = self.sections[self.section_index[key]]
+	if s then return s end
+
+	return config[key]
+end
+
+function config:write_config(filename)
 	if not filename then
 		filename = self.filename
 	end
@@ -171,7 +176,7 @@
 
 	for _, section in ipairs(self.sections) do
 		if getmetatable(section) == conf_section then
-			section:write(f)
+			section:write_section(f)
 		else
 			f:write(tostring(section))
 		end
@@ -190,7 +195,6 @@
 		value_index = {},
 	}
 	setmetatable(s, self)
-	self.__index = self
 	return s
 end
 
@@ -202,10 +206,15 @@
 end
 
 function conf_section:__index(key)
-	return self.values[self.value_index[key]]
-end
-
-function conf_section:write(f)
+	local v = self.values[self.value_index[key]]
+	if v then
+		return v[2]
+	end
+
+	return conf_section[key]
+end
+
+function conf_section:write_section(f)
 	f:write("[" .. self.name .. "]")
 	if self.template then
 		f:write("(!")

Modified: team/mnicholson/asttest/asttest/self-tests/astlib_configs/test.lua
URL: http://svn.asterisk.org/svn-view/asterisk/team/mnicholson/asttest/asttest/self-tests/astlib_configs/test.lua?view=diff&rev=193348&r1=193347&r2=193348
==============================================================================
--- team/mnicholson/asttest/asttest/self-tests/astlib_configs/test.lua (original)
+++ team/mnicholson/asttest/asttest/self-tests/astlib_configs/test.lua Fri May  8 13:46:54 2009
@@ -72,7 +72,7 @@
 s.inherit = {"template", "test"}
 s["value"] = "default"
 
-c:write()
+c:write_config()
 
 f = io.open("test.conf")
 test_conf = f:read("*a")




More information about the asterisk-commits mailing list