summaryrefslogtreecommitdiff
path: root/message.lua
blob: 834208e67f8296eb744c116788d2bc1def2f797a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
local class = require'r.class'

local BasePylon = require 'pylon'
local Thing = require 'thing'

local Message = class()
-- since this is the beating heart of wilson, it pays to do some validation
function Message.make(cls, self)
	setmetatable(self,cls)
	for k,v in pairs{
		pylon=BasePylon,
		channel=Thing,
		author=Thing,
	} do assert(class.is(self[k],v), 'field '..k..' missing or wrong') end
	assert(type(self.body)=='string','field body missing or wrong')
	assert(type(self.pylon_ids)=='table','field pylon_ids missing or wrong')
	assert(self.pylon_ids[self.pylon],'missing pylon_ids id for originating pylon!')
	assert(self.pylon == self.channel.pylon and self.pylon == self.author.pylon,
		"inconsistent pylons!")
	return self end
return Message