Permalink
Browse files

Allow gotoState to pass arguments to the new state.

  • Loading branch information...
1 parent 538de9b commit e697f87f8a59bb809ea023d674fc550cb35c61cb @TannerRogalsky TannerRogalsky committed Jan 10, 2013
Showing with 5 additions and 5 deletions.
  1. +5 −5 stateful.lua
View
@@ -89,8 +89,8 @@ local function _assertExistingState(self, state, stateName)
assert(state, "The state " .. stateName .. " was not found in " .. tostring(self.class) )
end
-local function _invokeCallback(self, state, callbackName)
- if state then state[callbackName](self) end
+local function _invokeCallback(self, state, callbackName, ...)
+ if state then state[callbackName](self, ...) end
end
local function _getCurrentState(self)
@@ -133,9 +133,9 @@ function Stateful.static:addState(stateName, superState)
return self.static.states[stateName]
end
-function Stateful:gotoState(stateName)
+function Stateful:gotoState(stateName, ...)
- _invokeCallback(self, _getCurrentState(self), 'exitedState')
+ _invokeCallback(self, _getCurrentState(self), 'exitedState', ...)
if stateName == nil then
self.__stateStack = { }
@@ -144,7 +144,7 @@ function Stateful:gotoState(stateName)
local newState = _getStateFromClassByName(self, stateName)
self.__stateStack = { newState }
- _invokeCallback(self, newState, 'enteredState')
+ _invokeCallback(self, newState, 'enteredState', ...)
end
end

0 comments on commit e697f87

Please sign in to comment.