https://github.com/mumez/sstate
A simple Finite State Machine for Smalltalk
https://github.com/mumez/sstate
fsm pharo smalltalk
Last synced: 4 months ago
JSON representation
A simple Finite State Machine for Smalltalk
- Host: GitHub
- URL: https://github.com/mumez/sstate
- Owner: mumez
- License: mit
- Created: 2020-05-28T13:44:20.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-01-21T05:18:33.000Z (almost 4 years ago)
- Last Synced: 2025-01-16T05:54:54.238Z (12 months ago)
- Topics: fsm, pharo, smalltalk
- Language: Smalltalk
- Size: 33.2 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SState
[](https://github.com/mumez/SState/actions/workflows/main.yml)
A simple Finite State Machine for Smalltalk
## Features
SState is a fairly simple FSM implementation, but is functional:
- You can add entry-action, exit-action and activity to State object.
- You can set transition action to Transition object.
- Supports guarded transition, auto transition, and decision.
- Hierarchical state machine support.
- StateMachine can handle both symbol and event object with possible arguments.
## Installation
```smalltalk
Metacello new
baseline: 'SState';
repository: 'github://mumez/SState/src';
load.
```
## Example
```smalltalk
stateMachine := SsStateMachine new.
stateA := (stateMachine addStateNamed: #stateA)
entryAction:[Transcript cr; show: 'entry stateA' ];
exitAction:[Transcript cr; show: 'exit stateA' ];
when: #toB to: #stateB;
when: #toC to: #stateC.
stateB := (stateMachine addStateNamed: #stateB)
when: #toA do: [Transcript cr; show: 'b->a'] to: #stateA.
stateC := (stateMachine addStateNamed: #stateC)
when: #toA do: [Transcript cr; show: 'c->a'] to: #stateA;
endWhen: #end.
stateMachine setStartStateTo: #stateA. "stateA entry-action fired"
stateMachine handleEvent: #toB. "stateA exit-action fired"
stateMachine handleEvent: #toA. "b->a transition action and stateA entry-action fired"
stateMachine handleEvent: #toC. "stateA exit-action fired"
stateMachine handleEvent: #bom. "Non-supposed events are ignored"
[stateMachine handleEvent: #boo] on: SsEventNotSupposed do: [:ex | ex inspect]. "But you can catch it if you like"
stateMachine handleEvent: #end.
stateMachine atEnd. "true"
```