A tiny double-stacked state manging library for Lua/LÖVE
Switch branches/tags
Nothing to show
Clone or download
S0lll0s
Latest commit ba0bfbd Feb 23, 2016
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example Fixes, example update Feb 23, 2016
spec Fixes, example update Feb 23, 2016
.travis.yml Add spec, rewrite 2.0 Feb 22, 2016
LICENSE Initial Commit Mar 30, 2015
README.md Fixes, example update Feb 23, 2016
st8.lua Fixes, example update Feb 23, 2016

README.md

St8.lua

A tiny double-stacked state manging library for Lua/LÖVE

Concept

St8 keeps two Stacks of States:

          Movement                            ^
         Input State                          | secondary stacks
Menu  -    Game      - Pause Menu Overlay     |
---------------primary stack--------------->

All States in the currently active Stack will run in parallel (i.e. receive events)

Usage

Require st8.lua to and keep the return value around. Call hook() to hook st8.lua up to the LÖVE handlers/callbacks. Using order(event, order) the execution order for a single event can be changed, pass anything but "bottom" or "bottom-up" to execute the events top-down. The bottom-up order is recommended for example for the draw callback.

You can add and remove Stacks (elements on the primary stack) using pause(state_or_stack) and resume().
You can add and remove States (elements on the secondary stack) using push(state) and pop().
You can swap States using swap(old, new) and remove a specific State using remove(state).

All methods accept additional arguments, these will be passed on both to the last State(s) and the new ones. pause accepts lists or single States as arguments.

Events

St8 covers all of LÖVE's callbacks. Event callback methods receive one additional parameter (as the first one). This is the return value of the State above the one receiving the event currently; For the topmost State it will always be nil. The return value of the last State of the current Stack will be returned. This can be used to pass messages between States of a Stack.

Example

You can find a small example showing off some of the features in the example folder.