mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-22 14:14:36 +00:00
[modified] state machine uses class
rather than own metatable management
This commit is contained in:
parent
02568f8f08
commit
1e07dd9746
@ -14,20 +14,21 @@
|
|||||||
TODO: consider coroutine friendliness
|
TODO: consider coroutine friendliness
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local state_machine = {}
|
local path = (...):gsub("state_machine", "")
|
||||||
state_machine._mt = {__index = state_machine}
|
local class = require(path .. "class")
|
||||||
|
|
||||||
|
local state_machine = class()
|
||||||
function state_machine:new(states, start)
|
function state_machine:new(states, start)
|
||||||
local ret = setmetatable({
|
self = self:init({
|
||||||
states = states or {},
|
states = states or {},
|
||||||
current_state = ""
|
current_state = ""
|
||||||
}, self._mt)
|
})
|
||||||
|
|
||||||
if start then
|
if start then
|
||||||
ret:set_state(start)
|
self:set_state(start)
|
||||||
end
|
end
|
||||||
|
|
||||||
return ret
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user