Difference between revisions of "Machine.initiate"

From OpenEUO
Jump to: navigation, search
(Created page with "== Calling Pattern == Call local m = sl.machine(a[,b]) -- later local r = m.initiate([d[,...]]) Args d1..dN optional are variadic arguments of any type Results r0..rN are va...")
 
m (Upon Error)
 
Line 44: Line 44:
 
== Upon Error ==
 
== Upon Error ==
  
Errors occurring in any of the state functions are reported and handled according to the operant error redirection mode.
+
Requesting a non-existent state key during any transition is an error.  Errors occurring in any of the state functions are reported and handled according to the operant error redirection mode
  
 
== See Also ==
 
== See Also ==

Latest revision as of 18:13, 3 January 2011

Calling Pattern

Call

local m = sl.machine(a[,b])
-- later
local r = m.initiate([d[,...]])

Args

d1..dN optional are variadic arguments of any type

Results

r0..rN are values returned by the a.exit function

Example Usage

local s = {
 initiate = function(h,...) local a = {...} print('initiating '..a[1]) return 'a' end,
 a        = function(h) print('a')       return 'b'    end,
 b        = function(h) print('b')       return 'c'    end,
 c        = function(h) print('c')       return 'exit' end,
 exit     = function(h) print('exiting') return 999    end,
 monitor  = function(s,h,n,g) if g=='exit' then h[1]=h[1]+1; if h[1]<3 then g='a' end end; return g end,
 }
local h = {0}
local m = sl.machine(s,h)
local n = m.initiate('live')
print(tostring(n))
--> initiating live
    a
    b
    c
    a
    b
    c
    a
    b
    c
    exiting
    999

Description

Calling initiate begins the execution of a previously defined state machine object by calling the function associated with the 'initiate' key in the state table. If no errors are encountered during execution, initiate returns the results returned by the 'exit' state function.

Upon Error

Requesting a non-existent state key during any transition is an error. Errors occurring in any of the state functions are reported and handled according to the operant error redirection mode

See Also