Page 1 of 1

A closure-based finite state machine (FSM) implementation

Posted: Mon Jul 29, 2019 9:43 am
by allsey87
Hi everyone,

I have created a minimalist synchronous finite state machine using Lua closures that some of you may be interested in. The repository is located on Github: https://github.com/allsey87/luafsm

Unlike other implementations, this has been written from scratch in Lua (it is not a port from another library) and is designed for expressing complex behavior in a modular way (e.g. complex hierarchies of substates can be generated using factories). Please use the issue tracker on Github if you find any bugs or would like me to add any features.

Have fun!

Re: A closure-based finite state machine (FSM) implementation

Posted: Mon Jul 29, 2019 1:29 pm
by pgimeno
Looks interesting. What's the license for using this library?

Re: A closure-based finite state machine (FSM) implementation

Posted: Mon Jul 29, 2019 1:36 pm
by YoungNeer
I always thought closures are useless in context of making games - but looks like you proved me wrong. I would like to know in which way were closures helpful to you. (Cause I always thought closures are not worth-learning if you only want to make games with lua)

Re: A closure-based finite state machine (FSM) implementation

Posted: Tue Jul 30, 2019 2:09 pm
by allsey87
pgimeno wrote: Mon Jul 29, 2019 1:29 pm Looks interesting. What's the license for using this library?
I have released it under an MIT license. The license is now included in the repository.
YoungNeer wrote: Mon Jul 29, 2019 1:36 pm I always thought closures are useless in context of making games - but looks like you proved me wrong. I would like to know in which way were closures helpful to you. (Cause I always thought closures are not worth-learning if you only want to make games with lua)
So closures in the case of this library are the states themselves which are runnable. You execute a state by running it. Since I wanted to avoid writing a function for every superstate (each of which would contain different child states), I just have a generic superstate factory function which generates closures containing the child states, exit, and entry functions as upvalues. I know that sounds a bit cryptic, but I think the only way to really get your head around it is to play with them for a bit.

Re: A closure-based finite state machine (FSM) implementation

Posted: Tue Jul 30, 2019 9:17 pm
by pgimeno
allsey87 wrote: Tue Jul 30, 2019 2:09 pm I have released it under an MIT license. The license is now included in the repository.
Thanks a lot!