You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MoonSC is an execution environment for
Harel statecharts
following the W3C SCXML Recommendation, capable
of running multiple concurrent SCXML sessions defined by statecharts written
as Lua tables.
It runs on GNU/Linux and requires Lua (>=5.3).
It should compile and run also on Windows (MSYS2/MinGW) and on MacOSX, but I've not
tested this yet (any feedback is appreciated).
Setup the build environment as described here, then:
$ git clone https://github.com/stetre/moonsc
$ cd moonsc
moonsc$ make
moonsc$ sudo make install
Example
The example below defines a simple statechart and executes it.
Other examples can be found in the examples/ and the tests/ directories.
-- MoonSC 'Hello World' example - hello.lualocalmoonsc=require("moonsc")
-- Import the element constructors:moonsc.import_tags()
-- Define a statechart using them:localhelloworld=_scxml{ name="hello", initial="s1",
_script{ text=[[print("Hello, World!")]] },
_state{ id="s1",
_onentry{ _log{ expr="'entering state s1'" } },
_transition{ event="go", target="s2",
_log{ expr=[["received event '".._event.name.."'"]] }
},
_onexit{ _log{ expr="'exiting state s1'" } },
},
_final{ id="s2",
_onentry{ _log{ expr="'entering state s2'" } },
_onexit{ _log{ expr="'exiting'" } },
},
}
-- Set a callback to redirect <log> executions to stdout:moonsc.set_log_callback(function(...) print(...) end)
-- Create a session with the statechart, start it, and send it an event:moonsc.create("mysession", helloworld)
moonsc.start("mysession")
moonsc.send("mysession", "go")
-- Enter the main event loop:whiletruedoifnotmoonsc.trigger() thenbreakendend
The script can be executed at the shell prompt with the standard Lua interpreter: