-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathseqand.lua
More file actions
55 lines (47 loc) · 1.42 KB
/
seqand.lua
File metadata and controls
55 lines (47 loc) · 1.42 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
--- Sequential-AND state example
-- This simple fsm demonstrates the use of sequential AND states.
local rfsm = require("rfsm")
local rfsm_ext = require("rfsm.ext")
local rfsmpp = require("rfsm.pp")
local state, conn, trans = rfsm.state, rfsm.conn, rfsm.trans
return state {
dbg=rfsmpp.gen_dbgcolor("parent"),
and_state = rfsm_ext.seqand {
seqanddbg=true,
-- define the order in which the subfsm shall be step'ed. The
-- list must not be exhaustive; all not mentioned states will be
-- after the ones listed in 'order' executed in arbitrary
-- ordering.
order = {'s2', 's1'},
entry=function() print("entering seqand") end,
exit=function() print("exiting seqand") end,
-- subfsm 1
s1=rfsm.init(
state {
dbg=rfsmpp.gen_dbgcolor("subfsm1"),
s11=state{},
s12=state{},
trans{src="initial", tgt="s11", },
trans{src="s11", tgt="s12", events={"e_one"}},
trans{src="s12", tgt="s11", events={"e_two"}},
}),
-- subfsm 2
s2=rfsm.init(
state {
dbg=rfsmpp.gen_dbgcolor("subfsm2"),
s21 = state {
doo = function(fsm)
while true do
print("hi from s2 doo!")
rfsm.yield(true)
end
end
},
trans{src="initial", tgt="s21" },
}),
},
off = state{},
trans{src="initial", tgt="off"},
trans{src="off", tgt="and_state", events={"e_on"}},
trans{src="and_state", tgt="off", events={"e_off"}},
}