scansion/generator.lua

Sun, 30 Dec 2018 09:43:36 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Sun, 30 Dec 2018 09:43:36 +0000
changeset 164
14500a149b31
parent 43
b37504fa3031
permissions
-rw-r--r--

client: Ignore timeout timer if we received a stanza

local it = require "scansion.iterators";

local script_methods = {};

local excluded_fields = { name = true, defined_line = true, type = true, annotation = true };
function script_methods:client(data)
	self:_append("["..data.name.."]");
	for k, v in pairs(data) do
		if not excluded_fields[k] then
			self:_append("", k..": "..v);
		end
	end
	self:_append("");
end

function script_methods:action(name, verb, data)
	if self.in_header then
		self.in_header = false;
		self:_append("----------");
		self:_append("");
	end
	
	self:_append(name.." "..verb..(data and ":" or ""));
	if data then
		for s in tostring(data):gmatch("[^\n]+") do
			self:_append("", s);
		end
	end
	self:_append("");
end

function script_methods:_append(...)
	local fields = { ... };
	for i = 1, select("#", ...) do
		fields[i] = tostring(fields[i]);
	end
	table.insert(self.lines, table.concat(fields, "\t"));
end

function script_methods:lines()
	return it.values(self.lines);
end

function script_methods:render()
	return table.concat(self.lines, "\n");
end

local script_mt = { __index = script_methods };

return {
	new_script = function ()
		return setmetatable({ in_header = true, n_clients = 0, clients = {} }, script_mt);
	end;
}

mercurial