Class Sequence
Sequence class.
A sequence object is an array of items, where each item can be a string or a function. When the sequence is converted to a string, the functions are executed and their return value is used. This allows for dynamic use of the "stack" based functions.
- calling on the object to instatiate it, passing the items as arguments
- concatenating two sequences with the "+" operator returns a new one of the 2 combined
- converting the sequence to a string will execute any functions and concatenate the results
- sequences can be nested inside other sequences
- sequence length is tracked in field
n
, if not present#sequence
is used (an empty sequence has non
field)
Example:
local Seq = require "terminal.sequence" local seq1 = Seq("hello", " ", "world") local seq2 = Seq("foo", function() return "---" end, "bar") -- functions as memebers local seq3 = seq1 + seq2 -- concatenation of sequences local seq4 = Seq(seq1, " ", seq2) -- nested sequences print(seq1) -- "hello world" print(seq2) -- "foo---bar" print(seq3) -- "hello worldfoo---bar" print(seq4) -- "hello world foo---bar"