Skip to content

Commit 0844fbe

Browse files
committed
Merge pull request #12 from Arkoniak/master
Documentation fix
2 parents 937e2eb + 9f527d3 commit 0844fbe

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ In addition, a generic `onstatechange()` callback can be used to call a single f
110110

111111
All callbacks will be passed the same arguments:
112112

113+
* **self**
113114
* **event** name
114115
* **from** state
115116
* **to** state
@@ -129,15 +130,17 @@ local fsm = machine.create({
129130
{ name = 'clear', from = 'yellow', to = 'green' }
130131
},
131132
callbacks = {
132-
onpanic = function(event, from, to, msg) print('panic! ' .. msg) end,
133-
onclear = function(event, from, to, msg) print('thanks to ' .. msg) end,
134-
ongreen = function(event, from, to) print('green light') end,
135-
onyellow = function(event, from, to) print('yellow light') end,
136-
onred = function(event, from, to) print('red light') end,
133+
onpanic = function(self, event, from, to, msg) print('panic! ' .. msg) end,
134+
onclear = function(self, event, from, to, msg) print('thanks to ' .. msg) end,
135+
ongreen = function(self, event, from, to) print('green light') end,
136+
onyellow = function(self, event, from, to) print('yellow light') end,
137+
onred = function(self, event, from, to) print('red light') end,
137138
}
138139
})
139140

141+
fsm:warn()
140142
fsm:panic('killer bees')
143+
fsm:calm()
141144
fsm:clear('sedatives in the honey pots')
142145
...
143146
```
@@ -148,7 +151,12 @@ Additionally, they can be added and removed from the state machine at any time:
148151
fsm.ongreen = nil
149152
fsm.onyellow = nil
150153
fsm.onred = nil
151-
fsm.onstatechange = function(event, from, to) print(to) end
154+
fsm.onstatechange = function(self, event, from, to) print(to) end
155+
```
156+
157+
or
158+
```lua
159+
function fsm:onstatechange(event, from, to) print(to) end
152160
```
153161

154162
Asynchronous State Transitions

0 commit comments

Comments
 (0)