diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-09-19 11:05:31 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-09-19 11:05:31 +0800 |
commit | 253b392a21b3e830f2bb2d2ed56157385017c6a8 (patch) | |
tree | 778a961ef1f7e2eedfd1cee329f3b59e3625b01b /server-beta/src | |
parent | c8a0d6924da782ad2c7266c4cf018fcc29c18336 (diff) | |
download | lua-language-server-253b392a21b3e830f2bb2d2ed56157385017c6a8.zip |
小酒馆
Diffstat (limited to 'server-beta/src')
-rw-r--r-- | server-beta/src/pub/brave.lua | 15 | ||||
-rw-r--r-- | server-beta/src/pub/init.lua | 1 | ||||
-rw-r--r-- | server-beta/src/pub/pub.lua | 48 | ||||
-rw-r--r-- | server-beta/src/pub/taskpad.lua | 15 | ||||
-rw-r--r-- | server-beta/src/pub/waiter.lua | 15 | ||||
-rw-r--r-- | server-beta/src/service.lua | 14 |
6 files changed, 108 insertions, 0 deletions
diff --git a/server-beta/src/pub/brave.lua b/server-beta/src/pub/brave.lua new file mode 100644 index 00000000..3cfa3e40 --- /dev/null +++ b/server-beta/src/pub/brave.lua @@ -0,0 +1,15 @@ +local thread = require 'bee.thread' + +---@class pub_brave +local mt = {} +mt.__index = mt +mt.type = 'pub.brave' + +return function (name) + log.info('Create pub brave:', name) + thread.newchannel(name) + local brave = setmetatable({ + channel = thread.channel(name), + }, mt) + return brave +end diff --git a/server-beta/src/pub/init.lua b/server-beta/src/pub/init.lua new file mode 100644 index 00000000..f15aa69e --- /dev/null +++ b/server-beta/src/pub/init.lua @@ -0,0 +1 @@ +return require 'pub.pub' diff --git a/server-beta/src/pub/pub.lua b/server-beta/src/pub/pub.lua new file mode 100644 index 00000000..6df8bb0b --- /dev/null +++ b/server-beta/src/pub/pub.lua @@ -0,0 +1,48 @@ +local thread = require 'bee.thread' +local taskpad = require 'pub.taskpad' +local waiter = require 'pub.waiter' +local brave = require 'pub.brave' + +---@class pub +local m = {} +m.type = 'pub' +m.waiters = {} +m.taskPads = {} +m.braves = {} + +--- 创建公告板,空闲的勇者会从公告板上领取任务 +function m:createTaskPads(num) + for _ = 1, num do + local n = #self.taskPads + 1 + self.taskPads[n] = taskpad('task' .. n) + end +end + +--- 雇佣看板娘,完成任务的勇者会到看板娘处交付任务 +function m:hireWaiters(num) + for _ = 1, num do + local n = #self.waiters + 1 + self.waiters[n] = waiter('waiter' .. n) + end +end + +--- 招募勇者,勇者会从公告板上领取任务,完成任务后到看板娘处交付任务 +function m:recruitBraves(num) + for _ = 1, num do + local n = #self.braves + 1 + self.braves[n] = brave('brave' .. n) + end +end + +function m:build() + thread.newchannel 'task0' + thread.newchannel 'bulletin' + thread.newchannel 'log' + + self.taskPads[0] = taskpad 'task0' + self.waiters[0] = waiter 'waiter0' + self.bulletin = thread.channel 'bulletin' + self.log = thread.channel 'log' +end + +return m diff --git a/server-beta/src/pub/taskpad.lua b/server-beta/src/pub/taskpad.lua new file mode 100644 index 00000000..4690fc2c --- /dev/null +++ b/server-beta/src/pub/taskpad.lua @@ -0,0 +1,15 @@ +local thread = require 'bee.thread' + +---@class pub_taskpad +local mt = {} +mt.__index = mt +mt.type = 'pub.taskpad' + +return function (name) + log.info('Create pub task pad:', name) + thread.newchannel(name) + local taskpad = setmetatable({ + channel = thread.channel(name), + }, mt) + return taskpad +end diff --git a/server-beta/src/pub/waiter.lua b/server-beta/src/pub/waiter.lua new file mode 100644 index 00000000..82decbab --- /dev/null +++ b/server-beta/src/pub/waiter.lua @@ -0,0 +1,15 @@ +local thread = require 'bee.thread' + +---@class pub_waiter +local mt = {} +mt.__index = mt +mt.type = 'pub.waiter' + +return function (name) + log.info('Create pub waiter:', name) + thread.newchannel(name) + local waiter = setmetatable({ + channel = thread.channel(name), + }, mt) + return waiter +end diff --git a/server-beta/src/service.lua b/server-beta/src/service.lua new file mode 100644 index 00000000..2cd9c940 --- /dev/null +++ b/server-beta/src/service.lua @@ -0,0 +1,14 @@ +local pub = require 'pub' +local thread = require 'bee.thread' + +local m = {} +m.type = 'service' + +function m:start() + pub:build() + pub:createTaskPads(4) + pub:hireWaiters(4) + pub:recruitBraves(4) +end + +return m |