Jump to content

Module:Buffer

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Codehydro (talk | contribs) at 00:06, 30 January 2015 (lovely little idea, no?). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

return setmetatable({
	__index = {
		_ = function(self, v)
			if v then
				table.insert(self, v)
			end
			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,
				v or nil
			}, getmetatable(self))
		end
	},
	__call = function(t, i)
		return table.concat(t, i)
	end
},
{__call = function(self, v)
	return setmetatable({v or nil}, self)
end
})