Added util.multitable.set

Sat, 27 Dec 2008 08:27:26 +0500

author
Waqas Hussain <waqas20@gmail.com>
date
Sat, 27 Dec 2008 08:27:26 +0500
changeset 650
674531bcb5c4
parent 649
5f8382768530
child 651
99f365b758f1

Added util.multitable.set

util/multitable.lua file | annotate | diff | comparison | revisions
--- a/util/multitable.lua	Fri Dec 26 21:48:08 2008 +0500
+++ b/util/multitable.lua	Sat Dec 27 08:27:26 2008 +0500
@@ -47,14 +47,25 @@
 	t_insert(t, (select(count, ...)));
 end
 
+local function set(self, ...)
+	local t = self.data;
+	local count = select('#', ...);
+	for n = 1,count-2 do
+		local key = select(n, ...);
+		local tab = t[key];
+		if not tab then tab = {}; t[key] = tab; end
+		t = tab;
+	end
+	t[(select(count-1, ...))] = (select(count, ...));
+end
+
 local function r(t, n, _end, ...)
 	if t == nil then return; end
-	if n > _end then
-		for key in pairs(t) do
-			t[key] = nil;
-		end
+	local k = select(n, ...);
+	if n == _end then
+		t[k] = nil;
+		return;
 	end
-	local k = select(n, ...);
 	if k then
 		v = t[k];
 		if v then
@@ -87,6 +98,7 @@
 		data = {};
 		get = get;
 		add = add;
+		set = set;
 		remove = remove;
 	};
 end

mercurial