diff options
| author | rebecca <ubq323@ubq323.website> | 2026-09-12 18:58:49 +0100 |
|---|---|---|
| committer | rebecca <ubq323@ubq323.website> | 2026-09-12 18:58:49 +0100 |
| commit | 90856a67fa2fa8061254006974b8921b4e97bc1a (patch) | |
| tree | cce28902a826d511b6bd38755c886746fe5cd18e /main.lua | |
| parent | 085040f49cc1386b294857aa68651329b0044420 (diff) | |
more oop refactoring
Diffstat (limited to 'main.lua')
| -rw-r--r-- | main.lua | 23 |
1 files changed, 10 insertions, 13 deletions
@@ -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() |
