feat(runtime): add read-through proxies on IECStringVar / IECWStringVar#156
Merged
Conversation
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>
3 tasks
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.
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 —IECStringVarwould otherwise expose nothing butget()/set()/operator=to its consumers.Add
length(),c_str(), andoperator[](read-only — returnschar/char16_tby value) on bothIECStringVar<MaxLen>andIECWStringVar<MaxLen>, routed through the force-aware value (forced_value_when forcing is active,value_otherwise). This mirrors howIECVar<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:Adding member operators on
IECStringVarwould risk overload ambiguity at ST call sites that currently bind to the free functions.Unlocks
name.length()/name.c_str()/name[i].Test plan
npm run buildsucceeds.npx vitest run tests/integration/st-validation.test.ts→ 64/64 green.iec_string.hpp/iec_wstring.hppintroduces an unintended overload (the design rationale for omitting==/!=proxies is documented in the source comments).🤖 Generated with Claude Code