aboutsummaryrefslogtreecommitdiffstats
path: root/alv/base
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-07-15 09:42:39 +0000
committers-ol <s-ol@users.noreply.github.com>2020-07-15 09:42:39 +0000
commit5c794916dcfecb6f54fdd28bbc1e119b596fce7f (patch)
treedf5bdeddeae5b7f6dd65e9f83187894cd320aaed /alv/base
parentadd vis field to Ops (diff)
downloadalive-5c794916dcfecb6f54fdd28bbc1e119b596fce7f.tar.gz
alive-5c794916dcfecb6f54fdd28bbc1e119b596fce7f.zip
Op: vis method instead of field
Diffstat (limited to 'alv/base')
-rw-r--r--alv/base/op.moon34
1 files changed, 20 insertions, 14 deletions
diff --git a/alv/base/op.moon b/alv/base/op.moon
index 625e1a8..f20518d 100644
--- a/alv/base/op.moon
+++ b/alv/base/op.moon
@@ -3,6 +3,7 @@
--
-- @classmod Op
import deep_copy, deep_iter, deep_map from require 'alv.util'
+import T from require 'alv.type'
class Op
--- members
@@ -22,8 +23,7 @@ class Op
fork: =>
out = if @out then @out\fork!
state = if @state then deep_copy @state
- vis = if @vis then deep_copy @vis
- @@ out, state, vis
+ @@ out, state
--- internal state of this Op.
--
@@ -32,16 +32,6 @@ class Op
--
-- @tfield table state
- --- visualisation data of this Op.
- --
- -- This may be any simple Lua value, including Lua tables, as long as it has
- -- no metatables, multiple references/loops, userdata etc.
- --
- -- This value is exposed to alv editors in order to render realtime
- -- visualisations overlaid onto the program text.
- --
- -- @tfield table vis
-
--- `Result` instance representing this Op's computed output value.
--
-- Must be set to a `Result` instance once `setup` finishes. Must not change
@@ -105,6 +95,23 @@ class Op
--- called when the Op is destroyed (optional).
destroy: =>
+ --- collect visualisation data (optional).
+ --
+ -- This may return any simple Lua value, including Lua tables, as long as it
+ -- has no metatables, multiple references/loops, userdata etc.
+ --
+ -- This value is exposed to alv editors in order to render realtime
+ -- visualisations overlaid onto the program text.
+ --
+ -- @treturn table vis
+ vis: =>
+ if @out and @out.metatype == '!'
+ { type: 'event' }
+ elseif @out and @out.type == T.bool
+ { type: 'bool' }
+ else
+ {}
+
--- implementation utilities.
--
-- super-methods and utilities for use by implementations.
@@ -118,8 +125,7 @@ class Op
-- @classmethod
-- @tparam ?Result out `out`
-- @tparam ?table state `state`
- -- @tparam ?table vis `vis`
- new: (@out, @state, @vis={}) =>
+ new: (@out, @state) =>
do_setup = (old, cur) ->
for k, cur_val in pairs cur