diff options
| author | s-ol <s+removethis@s-ol.nu> | 2025-09-22 15:41:55 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-09-22 15:41:55 +0000 |
| commit | 5e09bd7d0801c44cff80df8755751aa0ef748eb9 (patch) | |
| tree | 9fea18b18248895caa04a1a74531ad25238b5d43 | |
| parent | lib/love: tsv-output preserves canvas unless name/size changed (diff) | |
| download | alive-5e09bd7d0801c44cff80df8755751aa0ef748eb9.tar.gz alive-5e09bd7d0801c44cff80df8755751aa0ef748eb9.zip | |
global tag IDs
| -rw-r--r-- | alv-lib/glsl-view.moon | 16 | ||||
| -rw-r--r-- | alv-lib/love.moon | 4 | ||||
| -rw-r--r-- | alv/module.moon | 2 | ||||
| -rw-r--r-- | alv/registry.moon | 6 | ||||
| -rw-r--r-- | alv/tag.moon | 28 | ||||
| -rw-r--r-- | spec/internal/registry_spec.moon | 8 | ||||
| -rw-r--r-- | spec/internal/tag_spec.moon | 1 |
7 files changed, 35 insertions, 30 deletions
diff --git a/alv-lib/glsl-view.moon b/alv-lib/glsl-view.moon index bc783ed..4e79ec0 100644 --- a/alv-lib/glsl-view.moon +++ b/alv-lib/glsl-view.moon @@ -2,6 +2,8 @@ import Error, Constant, PureOp, Op, template_subst, Input, T, Array, Struct, sig import Message, Bundle, Timetag, add_item from require 'alv-lib._osc' import dns, udp from require 'socket' +fmttag = (tag) -> tag\ident!\gsub '[%.:%-/\\]', '_' + tryprefix = (prefix, filename) -> return filename unless prefix and filename\match '^%./' prefix .. filename @@ -85,14 +87,14 @@ video_source = Constant.meta args: args and Input.cold args samplertype = assert GLSL_SAMPLER_TYPES[@inputs.type!] - @setup_out '=', Uniform, type: samplertype, val: "alv-#{@tag}" + @setup_out '=', Uniform, type: samplertype, val: "alv-#{fmttag @tag}" tick: => { :socket, :type, :filename, :format, :args } = @unwrap_all! with @inputs.socket! filename = tryprefix @prefix, filename - msg = Message.new{ address: "/source/alv-#{@tag}/video", types: "ss", "TEXTURE_#{type}", filename } + msg = Message.new{ address: "/source/alv-#{fmttag @tag}/video", types: "ss", "TEXTURE_#{type}", filename } msg\add 's', format if format add_item msg, @inputs.args\type!, args if args \send Message.pack msg.content @@ -132,14 +134,14 @@ stream_source = Constant.meta args: args and Input.cold args samplertype = assert GLSL_SAMPLER_TYPES[@inputs.type!] - @setup_out '=', Uniform, type: samplertype, val: "alv-#{@tag}" + @setup_out '=', Uniform, type: samplertype, val: "alv-#{fmttag @tag}" tick: => { :socket, :name, :type, :filename, :format, :args } = @unwrap_all! with @inputs.socket! filename = tryprefix @prefix, filename - msg = Message.new{ address: "/source/alv-#{@tag}/stream", types: "ss", "TEXTURE_#{type}", filename } + msg = Message.new{ address: "/source/alv-#{fmttag @tag}/stream", types: "ss", "TEXTURE_#{type}", filename } msg\add 's', format if format add_item msg, @inputs.args\type!, args if args \send Message.pack msg.content @@ -165,13 +167,13 @@ tsv_source = Constant.meta type: Input.hot type or Constant.str "2D" samplertype = assert GLSL_SAMPLER_TYPES[@inputs.type!] - @setup_out '=', Uniform, type: samplertype, val: "alv-#{@tag}" + @setup_out '=', Uniform, type: samplertype, val: "alv-#{fmttag @tag}" tick: => { :socket, :name, :type } = @unwrap_all! with @inputs.socket! - \send Message.pack { address: "/source/alv-#{@tag}/tsv", types: "ss", "TEXTURE_#{type}", name } + \send Message.pack { address: "/source/alv-#{fmttag @tag}/tsv", types: "ss", "TEXTURE_#{type}", name } freeze = Constant.meta meta: @@ -235,7 +237,7 @@ shader_ = Constant.meta value: class extends PureOp pattern: const! + sig!^0 - name: (i) => "alv_u#{(tostring @tag)\gsub '%.', '_'}_#{i}" + name: (i) => "alv_u#{fmttag @tag}_#{i}" type: (args) => uniforms = {} diff --git a/alv-lib/love.moon b/alv-lib/love.moon index c29a2d4..9d3c64c 100644 --- a/alv-lib/love.moon +++ b/alv-lib/love.moon @@ -39,10 +39,10 @@ draw = Constant.meta num = shapes.num or #shapes for i=1, num do shapes[i] or= -> - COPILOT.drawlist[tostring @tag] = shapes + COPILOT.drawlist[@tag\ident!] = shapes destroy: => - COPILOT.drawlist[tostring @tag] = nil + COPILOT.drawlist[@tag\ident!] = nil group = Constant.meta meta: diff --git a/alv/module.moon b/alv/module.moon index 6eeb10b..d3fa5e5 100644 --- a/alv/module.moon +++ b/alv/module.moon @@ -14,7 +14,7 @@ class Module --- create a new Module. -- @classmethod new: => - @registry = Registry! + @registry = Registry @ --- check when the module source has last changed. -- @function poll diff --git a/alv/registry.moon b/alv/registry.moon index b625c1f..77aae7d 100644 --- a/alv/registry.moon +++ b/alv/registry.moon @@ -100,12 +100,16 @@ class Registry @last_map = {} + --- the module associated with this Registry + -- @tfield Module module + --- static functions -- @section static --- create a new Registry. -- @classmethod - new: => + -- @tparam Module module + new: (@module) => @last_map = {} { diff --git a/alv/tag.moon b/alv/tag.moon index 1ad9b28..070b0cd 100644 --- a/alv/tag.moon +++ b/alv/tag.moon @@ -37,6 +37,13 @@ class Tag assert parent, "need parent to clone!" ClonedTag @, parent + --- get a globally-unique identifier for this tag + -- + -- prepends the module name to the tag string + -- + -- @treturn string a unique string + ident: => "#{@registry.module\name!}:#{@}" + stringify: (depth=-1) => if @value and depth == -1 then "[#{@value}]" else '' __tostring: => if @value then "#{@value}" else '?' @@ -45,8 +52,8 @@ class Tag new: (@value) => if COPILOT and "string" != type @value - registry = COPILOT.active_module.registry - @pending = registry\register @ + @registry = COPILOT.active_module.registry + @pending = @registry\register @ --- get a unique index value for this Tag. -- @@ -66,6 +73,12 @@ class Tag assert either_or, "unexpected :set #{value} on #{@}" @value = value + --- the Registry associated with this Tag + -- @tfield Registry registry + + --- whether this Tag is newly assigned this tick + -- @tfield bool pending + --- static functions -- @section static @@ -80,8 +93,8 @@ class ClonedTag extends Tag if 'string' == type @original.value return - registry = COPILOT.active_module.registry - registry\register @ + @registry = COPILOT.active_module.registry + @registry\register @ @pending = @original.pending or @parent.pending @@ -96,12 +109,7 @@ class ClonedTag extends Tag @original\set value stringify: => error "cant stringify ClonedTag" - - __tostring: => - if @parent - "#{@parent}.#{@original}" - else - tostring @original + __tostring: => "#{@parent}.#{@original}" { :Tag diff --git a/spec/internal/registry_spec.moon b/spec/internal/registry_spec.moon deleted file mode 100644 index 4b0cfc3..0000000 --- a/spec/internal/registry_spec.moon +++ /dev/null @@ -1,8 +0,0 @@ -import Registry, Tag from require 'alv.registry' -import Logger from require 'alv.logger' -Logger\init 'silent' - -mk = -> - mock destroy: => - -describe 'registry', -> diff --git a/spec/internal/tag_spec.moon b/spec/internal/tag_spec.moon index 3fffcb7..851dbd9 100644 --- a/spec/internal/tag_spec.moon +++ b/spec/internal/tag_spec.moon @@ -1,6 +1,5 @@ import do_setup, do_teardown from require 'spec.test_setup' import Tag from require 'alv.tag' -import Registry from require 'alv.registry' before_each do_setup after_each do_teardown |
