aboutsummaryrefslogtreecommitdiffstats
path: root/alv
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
parentadd vis field to Ops (diff)
downloadalive-5c794916dcfecb6f54fdd28bbc1e119b596fce7f.tar.gz
alive-5c794916dcfecb6f54fdd28bbc1e119b596fce7f.zip
Op: vis method instead of field
Diffstat (limited to 'alv')
-rw-r--r--alv/base/op.moon34
-rw-r--r--alv/builtins.moon12
-rw-r--r--alv/copilot/udp.moon2
3 files changed, 27 insertions, 21 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
diff --git a/alv/builtins.moon b/alv/builtins.moon
index 12e78ba..d5d729c 100644
--- a/alv/builtins.moon
+++ b/alv/builtins.moon
@@ -309,8 +309,6 @@ switch_ = Constant.meta
if i\type! == T.bang
@state or= 1
- else
- @state = nil
super
i: Input.hot i
@@ -319,20 +317,22 @@ switch_ = Constant.meta
tick: =>
{ :i, :values } = @inputs
- ii = if i\type! == T.bang
+ if i\type! == T.bang
if i\dirty!
@state += 1
while @state >= #values
@state -= #values
@state
else
- switch i!
+ @state = switch i!
when true then 0
when false then 1
else (math.floor i!) % #values
+ @state
+
+ @out\set if v = values[@state + 1] then v!
- @vis.step = ii
- @out\set if v = values[ii + 1] then v!
+ vis: => step: @state
trace_ = Constant.meta
meta:
diff --git a/alv/copilot/udp.moon b/alv/copilot/udp.moon
index 5bf2ad4..7058b40 100644
--- a/alv/copilot/udp.moon
+++ b/alv/copilot/udp.moon
@@ -45,7 +45,7 @@ class UDPServer
if builtin and builtin.__class.__name ~= 'DummyReg'
res.head_meta = builtin.head.meta
res.result = encode_res builtin.node.result
- res.vis = if builtin.op then builtin.op.vis
+ res.vis = if builtin.op then builtin.op\vis!
res.kind = switch builtin.__class
when op_invoke then 'op'
when fn_invoke then 'fn'