kyleconroy / lua-state-machine Goto Github PK
View Code? Open in Web Editor NEWA finite state machine lua micro framework
License: MIT License
A finite state machine lua micro framework
License: MIT License
Hi, have the developers tried to add this library to a Defold project as a dependency? I'm able to attach other github releases on Defold, however for some reason this library doesn't load in.
local m = statemachine.create{
initial = "idle",
events = {
{name = "one", from = {"idle", "two"}, to = "one"},
{name = "two", from = {"one", "idle"}, to = "two"},
{name = "idle", from = {"one, two"}, to = "idle"},
}
}
print("idle", m.current)
m:one()
print("one", m.current)
m:idle()
print("idle", m.current)
produces output:
idle idle
one one
idle one
What's going on here? I've tried changing the event names to be different to the states they transition to, but I'm still having this problem.
I have a simple print in my call back and it prints two times. Is this what is supposed to happen? Other than that amazing!
It'd be awesome to have this package on LuaRocks, so that I can depend on it without having to copy files manually...
According to http://www.lua.org/pil/6.3.html lua supports tail calls, and the following example really gives infinite loop
function room1()
print("Room1")
return room2()
end
function room2()
print("Room2")
return room3()
end
function room3()
print("Room3")
return room1()
end
room1()
Yet, direct implementation of this code using lua-state-machine yields stack overflow
local machine = require 'statemachine'
local fsm = machine.create({
initial = 'room1',
events = {
{ name = 'go', from = 'room1', to = 'room2' },
{ name = 'go', from = 'room2', to = 'room3' },
{ name = 'go', from = 'room3', to = 'room1' },
},
callbacks = {
onroom1 = function(self, event, from, to) print("Room1"); return self:go() end,
onroom2 = function(self, event, from, to) print("Room2"); return self:go() end,
onroom3 = function(self, event, from, to) print("Room3"); return self:go() end,
}
})
fsm:go()
Well, may be I am not using it properly...
Hi - I plan to use your code in a game mod I'm developing. I'm wondering if you'd consider consuming XState configurations natively? Check out https://xstate.js.org/ and https://stately.ai/viz for examples of state machine configuration code. Let me know if you need more info or context.
Hi!
Can you make an example of the work for the state-machine state hero
I would have really helped this example to understand the state-machine.
Thank!
The current version, 1.0.0, is three years old.
I check the source code, and can't find anything about 'Asynchronous State Transitions'.
No machine.ASYNC, no machine.transition.
Readme is cheating me.
How can I list possible events from current state?
Just asking if it's possilble to implement a History state, as per https://stately.ai/docs/xstate-v5/history-states
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.