Skip to content

feat(runtime): add read-through proxies on IECStringVar / IECWStringVar#156

Merged
thiagoralves merged 1 commit into
developmentfrom
feat/string-var-proxies
Jun 2, 2026
Merged

feat(runtime): add read-through proxies on IECStringVar / IECWStringVar#156
thiagoralves merged 1 commit into
developmentfrom
feat/string-var-proxies

Conversation

@thiagoralves
Copy link
Copy Markdown
Contributor

Summary

Without these proxies, user code reading a STRING / WSTRING pin has to write name.get().c_str() / name.get().length() / name.get()[i] for every read — IECStringVar would otherwise expose nothing but get() / set() / operator= to its consumers.

Add length(), c_str(), and operator[] (read-only — returns char / char16_t by value) on both IECStringVar<MaxLen> and IECWStringVar<MaxLen>, routed through the force-aware value (forced_value_ when forcing is active, value_ otherwise). This mirrors how IECVar<T>::operator T() already exposes the underlying numeric for force-respecting reads on numeric pins.

Why comparison operators are NOT proxied

operator== / operator!= are intentionally left off the wrapper. The free-function overloads at the bottom of each header already cover every cross-class compare path:

inline bool operator==(const IECString<L1>& a, const IECStringVar<L2>& b)
inline bool operator==(const IECStringVar<L1>& a, const IECString<L2>& b)
inline bool operator==(const IECStringVar<L1>& a, const IECStringVar<L2>& b)
inline bool operator==(const IECStringVar<L1>& a, const char* b)
// + converse / IECVar wrappers

Adding member operators on IECStringVar would risk overload ambiguity at ST call sites that currently bind to the free functions.

Unlocks

  • openplc-editor PR #831 (c_blocks STRING/WSTRING standardization) — user C/C++ POU bodies can now read pins via plain name.length() / name.c_str() / name[i].
  • The matching openplc-web mirror PR will follow once this is released as v0.5.1.

Test plan

  • npm run build succeeds.
  • Integration tests pass: npx vitest run tests/integration/st-validation.test.ts → 64/64 green.
  • Reviewer: verify the integration test suite still passes in CI.
  • Reviewer: confirm no diagnostic on iec_string.hpp / iec_wstring.hpp introduces an unintended overload (the design rationale for omitting ==/!= proxies is documented in the source comments).

🤖 Generated with Claude Code

Without these proxies, user code reading a STRING / WSTRING pin has to
write `name.get().c_str()` / `name.get().length()` / `name.get()[i]`
for every read — `IECStringVar` would otherwise expose nothing but
`get()` / `set()` / `operator=` to its consumers.

Add `length()`, `c_str()`, and `operator[]` (read-only — returns char
by value) on both `IECStringVar<MaxLen>` and `IECWStringVar<MaxLen>`,
routed through the force-aware value (`forced_value_` when forcing is
active, `value_` otherwise).  This mirrors how `IECVar<T>::operator T()`
already exposes the underlying numeric for force-respecting reads on
numeric pins.

Comparison operators (`operator==` / `operator!=`) are intentionally
NOT proxied — the free-function overloads at the bottom of each
header already cover every cross-class compare path, and adding
member operators would risk overload ambiguity at ST call sites that
currently bind to the free functions.

Unlocks the openplc-editor / openplc-web c_blocks STRING/WSTRING
standardization PRs — user C/C++ POU code can now read pins via
plain `name.length()` / `name.c_str()` / `name[i]`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@thiagoralves thiagoralves merged commit 6f2f7b4 into development Jun 2, 2026
@thiagoralves thiagoralves deleted the feat/string-var-proxies branch June 2, 2026 17:32
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