Skip to content

Scripting depth: runtime context, first-class arrays, dedicated scripting docs#2

Merged
mbreissi merged 1 commit into
mainfrom
feat/scripting-depth-arrays-context
Jul 1, 2026
Merged

Scripting depth: runtime context, first-class arrays, dedicated scripting docs#2
mbreissi merged 1 commit into
mainfrom
feat/scripting-depth-arrays-context

Conversation

@mbreissi

@mbreissi mbreissi commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

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/script evaluation now binds, alongside the message view, the runtime context: thingName, componentName, componentFullName, routeId, and recvMs. A per-route ScriptContext is 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

aggregate now 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 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:

  • the two forms; the full scope (message view + runtime context); return / error / statelessness semantics
  • a Rhai language primer (functions, loops, ranges, switch, array map/filter/reduce)
  • array handling
  • a cookbook of 8 worked examples — derived units with a guard, array mean/peak/RMS, rate-of-change over samples, threshold-count filter, reusable identity-stamping, non-southbound normalization, switch status mapping, reduce — each explained goal → how → why, and each backed by a test in src/proc/script.rs.

explanation.md trimmed 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

  • 39 tests pass (9 new scripting/array example tests, so every documented script is verified); clippy clean; default + minimal feature sets build.
  • All internal doc links/anchors resolve.

🤖 Generated with Claude Code

…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
@mbreissi
mbreissi merged commit 26c7a58 into main Jul 1, 2026
2 checks passed
@mbreissi
mbreissi deleted the feat/scripting-depth-arrays-context branch July 5, 2026 05:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant