Awesome
MoonAgents: Reactive state machines in Lua
MoonAgents is a Lua module for event-driven concurrent programming.
It is designed after the concurrency model of the ITU-T Specification and Description Language (SDL) and provides functions for the implementation of systems composed of concurrent, reactive and intercommunicating finite state machines ('agents').
MoonAgents runs on GNU/Linux and on Windows (MSYS2/MinGW) and requires Lua (>=5.3).
Author: Stefano Trettel
(Note: MoonAgents is derived from LunaSDL, which it supersedes, and which is now discontinued. The major differences with LunaSDL are listed in the design notes document.)
License
MIT/X11 license (same as Lua). See LICENSE.
Documentation
See the Reference Manual.
Getting and installing
Setup the build environment as described here, then:
$ git clone https://github.com/stetre/moonagents
$ cd moonagents
moonagents$ make
moonagents$ sudo make install
Examples
The example below creates an agent that gives the traditional salute with a little delay (using a timer) and then stops.
Other examples can be found in the examples/ directory of this repo.
-- Hello World application - hello.lua
local moonagents = require("moonagents")
-- Create the system agent, from the script 'agent.lua':
local system = moonagents.create_system("HelloSystem","agent")
-- Enter the event loop:
while moonagents.trigger() do end
-- Agent script - agent.lua
local delay = 1.2 -- seconds
local T = moonagents.timer(delay,"T_EXPIRED")
local function Start()
print("Please, wait "..delay.." seconds ...")
moonagents.timer_start(T)
moonagents.next_state("Waiting")
end
local function TExpired()
print("... Hello World!")
moonagents.stop()
end
moonagents.start_transition(Start)
moonagents.transition("Waiting", "T_EXPIRED", TExpired)
The script can be executed at the shell prompt with the standard Lua interpreter:
$ lua hello.lua
See the examples/
directory.