Skip to content

Commit 965fbd9

Browse files
committed
update brave
1 parent 0b674d5 commit 965fbd9

File tree

10 files changed

+489
-173
lines changed

10 files changed

+489
-173
lines changed

channel_flow_test.lua

Lines changed: 0 additions & 57 deletions
This file was deleted.

main.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ ROOT = fs.path(util.expandPath(rootPath))
5353
LOGPATH = LOGPATH and util.expandPath(LOGPATH) or (ROOT:string() .. '/log')
5454
METAPATH = METAPATH and util.expandPath(METAPATH) or (ROOT:string() .. '/meta')
5555

56+
util.enableCloseFunction()
57+
util.enableFormatString()
58+
5659
---@diagnostic disable-next-line: deprecated
5760
debug.setcstacklimit(200)
5861
collectgarbage('generational', 10, 50)

script/brave/brave.lua

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ local thread = require 'bee.thread'
22
local channelMod = require 'bee.channel'
33
local selectMod = require 'bee.select'
44

5-
local taskPad = channelMod.query('taskpad')
6-
local waiter = channelMod.query('waiter')
7-
8-
assert(taskPad, 'taskpad channel not found')
9-
assert(waiter, 'waiter channel not found')
5+
local reqPad
6+
local resPad
107

118
---@class pub_brave
129
local m = {}
@@ -15,17 +12,26 @@ m.ability = {}
1512
m.queue = {}
1613

1714
--- 注册成为勇者
18-
function m.register(id, privatePad)
15+
---@param id integer
16+
---@param taskChName string
17+
---@param replyChName string
18+
function m.register(id, taskChName, replyChName)
1919
m.id = id
2020

21+
reqPad = channelMod.query(taskChName)
22+
resPad = channelMod.query(replyChName)
23+
24+
assert(reqPad, 'task channel not found: ' .. taskChName)
25+
assert(resPad, 'reply channel not found: ' .. replyChName)
26+
2127
if #m.queue > 0 then
2228
for _, info in ipairs(m.queue) do
23-
waiter:push(m.id, info.name, info.params)
29+
resPad:push(info.name, info.params)
2430
end
2531
end
2632
m.queue = nil
2733

28-
m.start(privatePad)
34+
m.start()
2935
end
3036

3137
--- 注册能力
@@ -35,8 +41,8 @@ end
3541

3642
--- 报告
3743
function m.push(name, params)
38-
if m.id then
39-
waiter:push(m.id, name, params)
44+
if m.id and resPad then
45+
resPad:push(name, params)
4046
else
4147
m.queue[#m.queue+1] = {
4248
name = name,
@@ -46,9 +52,7 @@ function m.push(name, params)
4652
end
4753

4854
--- 开始找工作
49-
function m.start(privatePad)
50-
local reqPad = privatePad and channelMod.query('req:' .. privatePad) or taskPad
51-
local resPad = privatePad and channelMod.query('res:' .. privatePad) or waiter
55+
function m.start()
5256
local selector = selectMod.create()
5357
selector:event_add(reqPad:fd(), selectMod.SELECT_READ)
5458

@@ -68,15 +72,15 @@ function m.start(privatePad)
6872
local ability = m.ability[name]
6973
-- TODO
7074
if not ability then
71-
resPad:push(m.id, id)
75+
resPad:push(id)
7276
log.error('Brave can not handle this work: ' .. name)
7377
goto CONTINUE
7478
end
7579
local ok, res = xpcall(ability, log.error, params)
7680
if ok then
77-
resPad:push(m.id, id, res)
81+
resPad:push(id, res)
7882
else
79-
resPad:push(m.id, id)
83+
resPad:push(id)
8084
end
8185
m.push('mem', collectgarbage 'count')
8286
::CONTINUE::

script/core/diagnostics/global-element.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ return function (uri, callback)
3939
return
4040
end
4141

42+
---@type table<string, boolean?>
4243
local definedGlobal = util.arrayToHash(config.get(uri, 'Lua.diagnostics.globals'))
4344
local definedGlobalRegex = config.get(uri, 'Lua.diagnostics.globalsRegex')
4445

script/core/diagnostics/lowercase-global.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ return function (uri, callback)
3838
return
3939
end
4040

41+
---@type table<string, boolean?>
4142
local definedGlobal = util.arrayToHash(config.get(uri, 'Lua.diagnostics.globals'))
4243
local definedGlobalRegex = config.get(uri, 'Lua.diagnostics.globalsRegex')
4344

script/plugins/ffi/init.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,13 @@ function m.compileCodes(codes)
351351
return lines
352352
end
353353

354+
---@param fileDir fs.path
354355
function m.build_single(codes, fileDir, uri)
355356
local texts = m.compileCodes(codes)
356357
if not texts then
357358
return
358359
end
359-
local fullPath = fileDir /ws.getRelativePath(uri)
360+
local fullPath = fileDir / ws.getRelativePath(uri)
360361

361362
if fullPath:stem():string():find '%.' then
362363
local newPath = fullPath:parent_path() / (fullPath:stem():string():gsub('%.', '/') .. ".lua")

0 commit comments

Comments
 (0)