Chain.initiate
Calling Pattern
Call
local c = sl.chain(a,b[,...]) -- later local i,j = chain.initiate([d[,...]])
Args
d1..dN optional are variadic arguments of any type
Results
i is a number j is a number
Example Usage
local b01 = function(n,...) 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 initiate begins the execution of a previously defined chain object. Each function in the chain body (b1..bN) is called with a set of variadic arguments in turn. The first set of arguments are the arguments supplied to the initiate call. The next set of arguments is the output of the first body function, and so on. The body index and output of each function is fed to the monitoring function, a, and if a returns true, the next function in the body is called and so on, until the end of the chain is reached. Initiate returns a tuple of the number of body functions executed and the total number of body functions.
Upon Error
Errors occurring in any of the chained functions are reported and handled according to the operant error redirection mode.