summaryrefslogtreecommitdiff
path: root/main.lua
diff options
context:
space:
mode:
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua23
1 files changed, 10 insertions, 13 deletions
diff --git a/main.lua b/main.lua
index 3f93cd9..61c75ef 100644
--- a/main.lua
+++ b/main.lua
@@ -1,4 +1,6 @@
local cqueues = require'cqueues'
+local class = require'r.class'
+
local config = require'config'
local Channel = require'channel'
@@ -9,18 +11,18 @@ local pylon_classes = {
nanochat_send = require'nanochat_send.pylon',
}
-local Wilson = {}
-function Wilson.make(conf)
- local self = {
+local Wilson = class()
+function Wilson.make(cls, conf)
+ local self = setmetatable({
pylons={},
busses={},
cq = cqueues.new(),
- }
+ }, Wilson)
for name, pylon_conf in pairs(conf.pylon) do
pylon_conf.name = name
local pylon_class = pylon_classes[pylon_conf.type]
assert(pylon_class, "no such pylon type "..pylon_conf.type)
- self.pylons[name] = pylon_class.make(self, pylon_conf)
+ self.pylons[name] = pylon_class:make(self, pylon_conf)
print("constructed pylon",name,pylon_conf.type)
end
for name, bus_conf in pairs(conf.bus) do
@@ -34,8 +36,7 @@ function Wilson.make(conf)
print("constructed bus ",name,'with '..#bus_conf..' channels')
self.busses[name] = bus
end
- return setmetatable(self, {__index=Wilson})
-end
+ return self end
-- find bus containing given channel
function Wilson._find_bus(self, channel)
@@ -59,16 +60,12 @@ function Wilson.run(self)
self.cq:wrap(pylon.run, pylon)
print("now running pylon", pylonname)
end
- for busname, bus in pairs(self.busses) do
- for _, channel in ipairs(bus) do
- channel.pylon:add_channel(channel)
- end
- end
print('toplevel',self.cq:loop())
+ cqueues.sleep(2)
end
local config_file = assert(io.open("wilson.ini","r"))
local conf = config.parse(config_file)
config_file:close()
-local wilson = Wilson.make(conf)
+local wilson = Wilson:make(conf)
wilson:run()