aboutsummaryrefslogtreecommitdiffstats
path: root/core/stream/base.moon
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-03-24 11:39:25 +0000
committers-ol <s-ol@users.noreply.github.com>2020-03-24 11:39:25 +0000
commit677c0d2f01e14bbeca1583ec7878d80c71c3aa68 (patch)
treecc20e04697da590b546de370599eeaaef647d20c /core/stream/base.moon
parentinternals/plugin-guide: first draft (diff)
downloadalive-677c0d2f01e14bbeca1583ec7878d80c71c3aa68.tar.gz
alive-677c0d2f01e14bbeca1583ec7878d80c71c3aa68.zip
Value -> Value/Event/IO-Stream
Close 12
Diffstat (limited to 'core/stream/base.moon')
-rw-r--r--core/stream/base.moon79
1 files changed, 79 insertions, 0 deletions
diff --git a/core/stream/base.moon b/core/stream/base.moon
new file mode 100644
index 0000000..ee4ee17
--- /dev/null
+++ b/core/stream/base.moon
@@ -0,0 +1,79 @@
+----
+-- base Stream interface.
+--
+-- implemented by `ValueStream`, `EventStream`, and `IOStream`.
+--
+-- @classmod Stream
+
+class Stream
+--- Stream interface.
+--
+-- Methods that have to be implemented by `Stream` implementations
+-- (`ValueStream`, `EventStream`, `IOStream`).
+--
+-- @section interface
+
+ --- return whether this Stream was changed in the current tick.
+ --
+ -- @function dirty
+ -- @treturn boolean
+
+ --- create a mutable copy of this Stream.
+ --
+ -- Used to insulate eval-cycles from each other.
+ --
+ -- @function fork
+ -- @treturn Stream
+
+ --- the type name of this Stream's value.
+ --
+ -- the following builtin typenames are used:
+ --
+ -- - `str` - strings, `value` is a Lua string
+ -- - `sym` - symbols, `value` is a Lua string
+ -- - `num` - numbers, `value` is a Lua number
+ -- - `bool` - booleans, `value` is a Lua boolean
+ -- - `bang` - trigger signals, `value` is a Lua boolean
+ -- - `opdef` - `value` is an `Op` subclass
+ -- - `builtin` - `value` is an `Action` subclass
+ -- - `fndef` - `value` is a `FnDef` instance
+ -- - `scope` - `value` is a `Scope` instance
+ --
+ -- @tfield string type
+
+ --- documentation metadata.
+ --
+ -- an optional table containing metadata for error messages and
+ -- documentation. The following keys are recognized:
+ --
+ -- - `name`: optional name
+ -- - `summary`: single-line description (markdown)
+ -- - `examples`: optional list of single-line code examples
+ -- - `description`: optional full-text description (markdown)
+ --
+ -- @tfield ?table meta
+
+ __tostring: =>
+ value = if @meta.name
+ @meta.name
+ else if 'table' == (type @value) and rawget @value, '__base'
+ @value.__name
+ else
+ tostring @value
+ "<#{@@__name} #{@type}: #{value}>"
+
+ __inherited: (cls) => cls.__base.__tostring = @__tostring
+
+--- static functions
+-- @section static
+
+ --- construct a new Stream.
+ --
+ -- @classmethod
+ -- @tparam string type the type name
+ -- @tparam ?table meta the `meta` table
+ new: (@type, @meta={}) =>
+
+{
+ :Stream
+}