<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.easyuo.com/openeuo/wiki/index.php?action=history&amp;feed=atom&amp;title=Machine</id>
		<title>Machine - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.easyuo.com/openeuo/wiki/index.php?action=history&amp;feed=atom&amp;title=Machine"/>
		<link rel="alternate" type="text/html" href="http://www.easyuo.com/openeuo/wiki/index.php?title=Machine&amp;action=history"/>
		<updated>2026-05-13T23:14:05Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.3</generator>

	<entry>
		<id>http://www.easyuo.com/openeuo/wiki/index.php?title=Machine&amp;diff=1191&amp;oldid=prev</id>
		<title>Ximan: /* State Function Prototypes */</title>
		<link rel="alternate" type="text/html" href="http://www.easyuo.com/openeuo/wiki/index.php?title=Machine&amp;diff=1191&amp;oldid=prev"/>
				<updated>2011-01-04T00:37:13Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;State Function Prototypes&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 00:37, 4 January 2011&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l61&quot; &gt;Line 61:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 61:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; a.exit = function(b)&amp;#160; return r end&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; a.exit = function(b)&amp;#160; return r end&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;If the optional monitor function is provided, it receives as arguments a reference to the state function table, the b table, the last state key, and the requested transition state key.&amp;#160; Monitor should return the key representing the next state to transition into, either echoing the requested key or overriding it.&amp;#160; &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;If the optional monitor function is provided, it receives as arguments a reference to the state function table, the b table, the last state key &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;l&lt;/ins&gt;, and the requested transition state key &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;n&lt;/ins&gt;.&amp;#160; Monitor should return the key representing the next state to transition into, either echoing the requested key or overriding it.&amp;#160; &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; -- optional monitor function&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; -- optional monitor function&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; a.monitor = function(a,b,&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;n&lt;/del&gt;,&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;g&lt;/del&gt;)&amp;#160; return &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;g &lt;/del&gt;end&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; a.monitor = function(a,b,&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;l&lt;/ins&gt;,&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;n&lt;/ins&gt;)&amp;#160; return &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;n &lt;/ins&gt;end&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Upon Error ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Upon Error ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ximan</name></author>	</entry>

	<entry>
		<id>http://www.easyuo.com/openeuo/wiki/index.php?title=Machine&amp;diff=1190&amp;oldid=prev</id>
		<title>Ximan: Created page with &quot;== Calling Pattern == Call  local m = sl.machine(a[,b]) Args  a is a table of functions  b optional, is a table Results  m is a machine closure  == Closure Methods ==  * [[machin...&quot;</title>
		<link rel="alternate" type="text/html" href="http://www.easyuo.com/openeuo/wiki/index.php?title=Machine&amp;diff=1190&amp;oldid=prev"/>
				<updated>2011-01-04T00:35:44Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;== Calling Pattern == Call  local m = sl.machine(a[,b]) Args  a is a table of functions  b optional, is a table Results  m is a machine closure  == Closure Methods ==  * [[machin...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Calling Pattern ==&lt;br /&gt;
Call&lt;br /&gt;
 local m = sl.machine(a[,b])&lt;br /&gt;
Args&lt;br /&gt;
 a is a table of functions&lt;br /&gt;
 b optional, is a table&lt;br /&gt;
Results&lt;br /&gt;
 m is a machine closure&lt;br /&gt;
&lt;br /&gt;
== Closure Methods ==&lt;br /&gt;
&lt;br /&gt;
* [[machine.initiate]]&lt;br /&gt;
&lt;br /&gt;
== Example Usage ==&lt;br /&gt;
 local s = {&lt;br /&gt;
   initiate = function(h,...) local a = {...} print('initiating '..a[1]) return 'a' end,&lt;br /&gt;
   a        = function(h) print('a')       return 'b'    end,&lt;br /&gt;
   b        = function(h) print('b')       return 'c'    end,&lt;br /&gt;
   c        = function(h) print('c')       return 'exit' end,&lt;br /&gt;
   exit     = function(h) print('exiting') return 999    end,&lt;br /&gt;
   monitor  = function(s,h,n,g) if g=='exit' then h[1]=h[1]+1; if h[1]&amp;lt;3 then g='a' end end; return g end,&lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
 local h = {0}&lt;br /&gt;
 local m = sl.machine(s,h)&lt;br /&gt;
 local n = m.init('live')&lt;br /&gt;
 print(tostring(n))&lt;br /&gt;
&lt;br /&gt;
 --&amp;gt; initiating live&lt;br /&gt;
     a&lt;br /&gt;
     b&lt;br /&gt;
     c&lt;br /&gt;
     a&lt;br /&gt;
     b&lt;br /&gt;
     c&lt;br /&gt;
     a&lt;br /&gt;
     b&lt;br /&gt;
     c&lt;br /&gt;
     exiting&lt;br /&gt;
     999&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
Calling machine returns a state machine closure with one defined method, [[machine.initiate]].  The first argument, a, is the table of state functions, and b is an optional table passed to each state function upon transition into its corresponding state.  If b isn't provided, then b is set to a newly created empty table.&lt;br /&gt;
&lt;br /&gt;
== State Function Prototypes ==&lt;br /&gt;
&lt;br /&gt;
The state table must provide function values for at least two keys: 'initiate' and 'exit'.  The initiate function receives the optional argument b upon initialization (or a newly created empty table if it isn't) as well as any variadic arguments from the machine.initiate call, and should the key representing the next state to transition into.&lt;br /&gt;
&lt;br /&gt;
 -- initiate function&lt;br /&gt;
 a.initiate = function(b, ...) return 'c' end&lt;br /&gt;
&lt;br /&gt;
A typical state function receives b as its sole argument, and should return the key representing the next state to transition into.&lt;br /&gt;
&lt;br /&gt;
 -- a typical state function&lt;br /&gt;
 a.c = function(b)  return 'c' end&lt;br /&gt;
&lt;br /&gt;
The exit function receives b as its sole argument, and its return value will be echoed as the return value of machine.initiate if no errors occur during the execution of the state machine.&lt;br /&gt;
&lt;br /&gt;
 -- exit function&lt;br /&gt;
 a.exit = function(b)  return r end&lt;br /&gt;
&lt;br /&gt;
If the optional monitor function is provided, it receives as arguments a reference to the state function table, the b table, the last state key, and the requested transition state key.  Monitor should return the key representing the next state to transition into, either echoing the requested key or overriding it.  &lt;br /&gt;
&lt;br /&gt;
 -- optional monitor function&lt;br /&gt;
 a.monitor = function(a,b,n,g)  return g end&lt;br /&gt;
&lt;br /&gt;
== Upon Error ==&lt;br /&gt;
&lt;br /&gt;
If the described argument pattern isn't matched or the required state keys aren't available, an error is reported and handled according to the operant error redirection mode.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.easyuo.com/openeuo/wiki/index.php/Simplelib simplelib]&lt;br /&gt;
&lt;br /&gt;
* [[case]]&lt;br /&gt;
* [[chain]]&lt;br /&gt;
* [[iterator]]&lt;br /&gt;
* [[spin]]&lt;/div&gt;</summary>
		<author><name>Ximan</name></author>	</entry>

	</feed>