Last active
November 4, 2018 17:38
-
-
Save frame-lang/7fe5daa32270844c03c74b9992a4c027 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 // | |
// // | |
//-------------------------------------------------// | |
#Dorthy | |
-machine- | |
$Begin | |
|start| | |
print("Starting") | |
-> $Kansas ^ | |
|enter| print("Never called!") ^ | |
|exit| print("Dim the lights!") ^ | |
$Kansas | |
|enter| print("That dog's a menace to the community.") ^ | |
|tornado| -> $Oz ^ | |
|exit| print("Aunty Em!") ^ | |
$Oz | |
|enter| print("We aren't in Kansas anymore") ^ | |
|3 heel clicks| -> $Kansas ^ | |
|exit| print("There's no place like home!") ^ | |
//-------------------------------------------------// | |
// // | |
// Implementation // | |
// // | |
//-------------------------------------------------// | |
class Dorthy { | |
// -machine- | |
var _state(e:FrameEvent) = Begin | |
/********************************** | |
$Begin | |
|start| | |
print("Starting") | |
-> $Kansas ^ | |
|enter| print("Never called!") ^ | |
|exit| print("Dim the lights!") ^ | |
***********************************/ | |
func Begin(e:FrameEvent) { | |
if (e._msg == "start") { | |
print("Starting") | |
_transition(Kansas) | |
return | |
} | |
if (e._msg == "enter") { | |
print("Never called!") | |
return | |
} | |
if (e._msg == "exit") { | |
print("Dim the lights!") | |
return | |
} | |
} | |
/********************************** | |
$Kansas | |
|enter| print("That dog's a menace to the community.") ^ | |
|tornado| -> $Oz ^ | |
|exit| print("Aunty Em!") ^ | |
***********************************/ | |
func Kansas(e:FrameEvent) { | |
if (e._msg == "enter") { | |
print("That dog's a menace to the community.") | |
return | |
} | |
if (e._msg == "tornado") { | |
_transition(Oz) | |
return | |
} | |
if (e._msg == "exit") { | |
print("Aunty Em!") | |
return | |
} | |
} | |
/********************************** | |
$Oz | |
|enter| print("We aren't in Kansas anymore") ^ | |
|3 heel clicks| -> $Kansas ^ | |
|exit| print("There's no place like home!") ^ | |
***********************************/ | |
func Oz(e:FrameEvent) { | |
if (e._msg == "enter") { | |
print("We aren't in Kansas anymore") | |
return | |
} | |
if (e._msg == "3 heel clicks") { | |
_transition(Kansas) | |
return | |
} | |
if (e._msg == "exit") { | |
print("There's no place like home!") | |
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