Module:Buffer: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
en>Codehydro
(lovely little idea, no?)
 
en>Codehydro
(convert non-nil/boolean to string)
Line 1: Line 1:
return setmetatable({
return setmetatable({
__index = {
__index = {
_ = function(self, v)
check = function(v)
if v then
if v and v ~= true then
if type(v) == 'table' then
table.insert(self, v)
return getmetatable(v) and getmetatable(v).__tostring and
tostring(v)
or table.concat(v)
end
return v--i.e. numbers or strings
end
end
end,
_ = function(self, v)
table.insert(self, self.check(v))
return self
return self
end,
end,
Line 19: Line 27:
return parent or child
return parent or child
end,
end,
v or nil
self.check(v)
}, getmetatable(self))
}, getmetatable(self))
end
end
Line 28: Line 36:
},
},
{__call = function(self, v)
{__call = function(self, v)
return setmetatable({v or nil}, self)
return setmetatable({self.check(v)}, self)
end
end
})
})

Revision as of 02:58, 30 January 2015

Documentation for this module may be created at Module:Buffer/doc

return setmetatable({
	__index = {
		check = function(v)
			if v and v ~= true then
				if type(v) == 'table' then
					return getmetatable(v) and getmetatable(v).__tostring and
						tostring(v)
						or table.concat(v)
				end
				return v--i.e. numbers or strings
			end
		end,
		_ = function(self, v)
			table.insert(self, self.check(v))
			return self
		end,
		_in = function(self, v)
			return setmetatable({
				parent = self,
				_out = function(child, v2, outs)
					local parent = child.parent:_(child(v2))
					if outs and outs > 0 then repeat
						child = parent
						parent = parent.parent
						outs = parent and parent:_(child()) and (outs - 1) or 0
					until outs == 0 end
					return parent or child
				end,
				self.check(v)
			}, getmetatable(self))
		end
	},
	__call = function(t, i)
		return table.concat(t, i)
	end
},
{__call = function(self, v)
	return setmetatable({self.check(v)}, self)
end
})