Last active
October 31, 2018 01:44
-
-
Save frame-lang/d76a834422b038e21ed9713f39fe36cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//-------------------------------------------------// | |
// // | |
// FMN // | |
// // | |
//-------------------------------------------------// | |
#Transition2 | |
-machine- | |
$Begin | |
|start| initialize() -> $Working ^ | |
$Working => $Default | |
|enter| startWorking ^ | |
|exit| stopWorking ^ | |
$End | |
|enter| cleanup() ^ | |
$Default | |
|stop| -> $End ^ | |
//-------------------------------------------------// | |
// // | |
// Implementation // | |
// // | |
//-------------------------------------------------// | |
class Transition2 { | |
// -machine- | |
var _state(e:FrameEvent) = Begin | |
/********************************** | |
$Begin | |
|start| -> $S1 | |
***********************************/ | |
func Begin(e:FrameEvent) { | |
if (e._msg == "start") { | |
_transition(S1) | |
return | |
} | |
} | |
/********************************** | |
$S1 | |
|enter| print("Welcome to $S1!") ^ | |
|toggle| -> $S2 ^ | |
|exit| print("Goodbye from $S1!") ^ | |
***********************************/ | |
func S1(e:FrameEvent) { | |
if (e._msg == "enter") { | |
print("Welcome to $S1!") | |
return | |
} | |
if (e._msg == "toggle") { | |
_transition(S2) | |
return | |
} | |
if (e._msg == "exit") { | |
print("Goodbye from $S1!") | |
return | |
} | |
} | |
/********************************** | |
$S2 | |
|enter| print("Welcome to $S2!") ^ | |
|toggle| -> $S1 ^ | |
|exit| print("Goodbye from $S2!") ^ | |
***********************************/ | |
func S2(e:FrameEvent) { | |
if (e._msg == "enter") { | |
print("Welcome to $S2!") | |
return | |
} | |
if (e._msg == "toggle") { | |
_transition(S1) | |
return | |
} | |
if (e._msg == "exit") { | |
print("Goodbye from $S2!") | |
return | |
} | |
} | |
// machinery | |
func _transition(newState:FrameState) { | |
_state(new FrameEvent("exit")) | |
_state = newState | |
_state(new FrameEvent("enter")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment