I mostly like this. The only gripe I have with it is the stringly-typed way of triggering events. It seems like you might be able to better leverage the type system to ensure that spelling mistakes or fat-fingerings don't cause a runtime error sometime in the future. If the .Event() method took an object that satisfied the "Trigger" (or something) interface, instead of just a string, you might be able to catch those kinds of errors during compile-time instead.
Thanks for the feedback! It's a good suggestion, and having something else than strings as events is something that I have analyzed. Currently different handlers depends on string operations as selectors, for example "before_<event>". Any ideas on how to move that to the static type world (preferably without using the reflect package)?
That looks really cool, awesome to be able to generate static FSM code. I use my FSM (and started to use Jake Gordon's) when I need a lightweight state variable, a step up from a collection of bools when it starts to get messy with lots of ands and ors.
4 comments
[ 3.0 ms ] story [ 17.3 ms ] threadZed Shaw wrote a great essay about state charts in Ragel:
http://www.zedshaw.com/essays/ragel_state_charts.html
The official docs:
http://www.complang.org/ragel/ragel-guide-6.8.pdf