Difference between revisions of "Chain"
From OpenEUO
(Created page with "== Calling Pattern == Call local c = sl.chain(a,b[,...]) Args a is a function b1..bN are functions Results c is a chain closure == Alternative Calling Pattern == Call local...") |
m (→Description) |
||
(One intermediate revision by the same user not shown) | |||
Line 51: | Line 51: | ||
Calling chain returns a chain closure with two defined methods, [[chain.dispose|dispose]] and [[chain.initiate|initiate]]. The first argument, a, is the monitoring function, and the remaining functions (or a table of functions) make up the body of the execution chain. | Calling chain returns a chain closure with two defined methods, [[chain.dispose|dispose]] and [[chain.initiate|initiate]]. The first argument, a, is the monitoring function, and the remaining functions (or a table of functions) make up the body of the execution chain. | ||
− | + | Upon initialization, functions passed as the b arguments to chain are called in turn and their results are passed to the a function. If a returns true, the next argument in the chain is executed. See the [[chain.initiate|initiate]] method for more details. | |
== Upon Error == | == Upon Error == |
Latest revision as of 16:01, 18 December 2010
Contents
Calling Pattern
Call
local c = sl.chain(a,b[,...])
Args
a is a function b1..bN are functions
Results
c is a chain closure
Alternative Calling Pattern
Call
local c = sl.chain(a,t)
Args
a is a function t is a table of functions with one-based, contiguous numeric keys
Results
c is a chain closure
Closure Methods
Example Usage
local b01 = function(n,a,b,c) print(n) return true end local b02 = function(a,b,c) print(a..' '..b..' '..c) return string.char(string.byte(a)+1), string.char(string.byte(b)+1), string.char(string.byte(c)+1) end local b05 = {b02,b02,b02} local b00 = sl.chain(b01,b05) local b03, b04 = b00.init('a','b','c') print(b03) print(b04) b00.dispose()
--> a b c 1 b c d 2 c d e 3 3
Description
Calling chain returns a chain closure with two defined methods, dispose and initiate. The first argument, a, is the monitoring function, and the remaining functions (or a table of functions) make up the body of the execution chain.
Upon initialization, functions passed as the b arguments to chain are called in turn and their results are passed to the a function. If a returns true, the next argument in the chain is executed. See the initiate method for more details.
Upon Error
If none of the described argument patterns are matched, an error is reported and handled according to the operant error redirection mode.