Scripting depth: runtime context, first-class arrays, dedicated scripting docs#2
Merged
Merged
Conversation
…ted scripting docs Addresses three depth gaps in the v2 scripting/array support. 1. Runtime context in the script scope. Every filter/script evaluation now also binds thingName / componentName / componentFullName / routeId / recvMs (a per-route ScriptContext threaded app→pipeline→filter/script→RhaiEval), so a generic, reusable script can stamp or branch on which component/route/thing it runs in instead of hard-coding those values. 2. First-class array-typed values. The aggregate stage folds an array value element-wise (recurse in Acc::fold_value), so an OPC UA array node / vector signal feeds avg/min/max/sum/count across its elements rather than being dropped as non-numeric. (Array values already flow through filter `[]` spread, scripts as Rhai arrays, and the file sink as JSON / explode.) 3. Dedicated, substantive scripting documentation. New docs/scripting.md: the two forms, the full scope (message view + runtime context), return/error/stateless semantics, a Rhai language primer (fn, loops, ranges, switch, array map/filter/reduce), array handling, and a cookbook of 8 worked examples with goal→how→why prose — every example backed by a test in src/proc/script.rs. Explanation trimmed to an overview that links out; reference scope table, a new "Handle array-valued signals" how-to, data-types array note, and the docs index updated. 39 tests pass (incl. 9 new scripting/array example tests); clippy clean; default + minimal feature sets build. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FVhxGPCfUC15E58XQbYPwk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses three depth gaps called out in review — the v2 scripting/array work covered the simplest cases only. This makes each first-class.
1. Runtime context injected into the script scope
Every
filter/scriptevaluation now binds, alongside the message view, the runtime context:thingName,componentName,componentFullName,routeId, andrecvMs. A per-routeScriptContextis threaded app → pipeline → filter/script →RhaiEval. This lets a single generic script be reused across components and still stamp/branch on where it runs, instead of hard-coding identity.2. First-class array-typed values
aggregatenow folds an array value element-wise (recurse inAcc::fold_value), so an OPC UA array node / vector signal feedsavg/min/max/sum/countacross its elements rather than being dropped as non-numeric. Array values already flowed through the[]filter/key spread, scripts (as Rhai arrays), and the file sink (JSON /explode) — now they aggregate too, and it's documented end to end.3. Dedicated, substantive scripting documentation
New
docs/scripting.md— its own page — replaces the thin section:switch, arraymap/filter/reduce)switchstatus mapping,reduce— each explained goal → how → why, and each backed by a test insrc/proc/script.rs.explanation.mdtrimmed to an overview that links out; the reference scope table, a new "Handle array-valued signals" how-to, a data-types array note, and the docs index are updated.Validation
clippyclean; default + minimal feature sets build.🤖 Generated with Claude Code