[modified] state machine uses class rather than own metatable management

This commit is contained in:
Max Cahill 2020-04-07 13:53:28 +10:00
parent 02568f8f08
commit 1e07dd9746

View File

@ -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
------------------------------------------------------------------------------- -------------------------------------------------------------------------------