-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbt.lua
More file actions
57 lines (36 loc) · 1.02 KB
/
bt.lua
File metadata and controls
57 lines (36 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
local _M = {}
function _M.new( self , _root )
return setmetatable({
root = _root,
},{__index = _M })
end
--
function _M.describe(self , ...)
local args = { ... }
for i = 1 , #args do
local arg = args[i]
print( 'arg:' .. arg )
end
self:loop( self.root , ... )
end
--遍历路径
function _M:loop( node , ...)
if node.selector then --选择节点
for i , v in pairs(node.selector) do --继续遍历
if v.condition( self , ... ) then
self:loop( v , ...) break
end
end
elseif node.sequence then --顺序执行
for i , v in pairs(node.sequence) do --继续遍历
self:loop(v,...) break
end
elseif node.parallel then -- 并行执行
for i , v in pairs(node.parallel) do
self.loop( v , ... ) break
end
elseif node.action then --执行节点
node.action(self,...) --执行动作
end
end
return _M