git.s-ol.nu alive / ed7f3e2
allow top-level input in Op.inputs s-ol 1 year, 12 days ago
2 changed file(s) with 14 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
139139 new: (@out, @state) =>
140140
141141 do_setup = (old, cur) ->
142 for k, cur_val in pairs cur
143 old_val = old and old[k]
142 -- are these inputs or nested tables?
143 old_plain = old and not old.__class
144 cur_plain = cur and not cur.__class
144145
145 -- are these inputs or nested tables?
146 cur_plain = cur_val and not cur_val.__class
147 old_plain = old_val and not old_val.__class
146 if cur_plain
147 -- both are tables, recurse
148 for k, cur_nest in pairs cur
149 do_setup (old and old[k]), cur_nest
150 elseif cur and not (cur_plain or old_plain)
151 -- both are streams (or nil), setup them
152 cur\setup old
148153
149 if cur_plain
150 -- both are tables, recurse
151 do_setup old_val, cur_val
152 elseif not (cur_plain or old_plain)
153 -- both are streams (or nil), setup them
154 cur_val\setup old_val
155154 --- setup previous `inputs`, if any, with the new inputs, and write them to
156155 -- `inputs`. The `inputs` table can be nested with string or integer keys,
157156 -- but all leaf-entries must be `Input` instances. It must not contain loops
4949
5050 --- yield all leaf values in a table
5151 deep_iter = (table) ->
52 for k, v in pairs table
53 if is_plain_table v
52 if is_plain_table table
53 for k, v in pairs table
5454 deep_iter v
55 else
56 coroutine.yield v
55 else
56 coroutine.yield table
5757
5858 {
5959 :opairs