@@ -110,6 +110,7 @@ In addition, a generic `onstatechange()` callback can be used to call a single f
110110
111111All 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 ()
140142fsm :panic (' killer bees' )
143+ fsm :calm ()
141144fsm :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:
148151fsm .ongreen = nil
149152fsm .onyellow = nil
150153fsm .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
154162Asynchronous State Transitions
0 commit comments