Fix WASM binding resolution across module scopes - #154
Conversation
jankiluitel
left a comment
There was a problem hiding this comment.
Reviewed the changes and the updated binding resolution approach looks good. The fallback handling across different module scopes improves robustness while keeping the change focused. The implementation is clear and the existing checks are passing. Approved from my side. ✅
Rhinoatron
left a comment
There was a problem hiding this comment.
Amazing work on the change it's focused and fits the follow up runtime stability work described in the task notes. The updated binding resolution logic looks clearer and safer than the previous eval(name) approach. The fallback checks across globalThis, the WASM/iframe scope, _CPP_ names, and __sklib__-prefixed names make sense for improving C# WASM runtime stability and browser execution reliability. I also checked for related PRs. I found #147, which is still open and touches the same C# WASM binding-loading area, but this PR appears to be a more specific and current fix. It may be worth confirming with the mentor whether #147 should be closed or superseded so there is no confusion. Approved.
Summary
Generated C# WASM bindings were failing to load and initialise correctly at runtime. The lookup in
CSharpWasmExpo/main.jsthat resolves each binding method against the WASM module scope only checked a single naming pattern, so methods exposed under a different scope or naming convention (e.g.__sklib_-prefixed keys) were silently missed.Change
Updated the binding resolution logic in
CSharpWasmExpo/main.jsto fall back through multiple lookup strategies when resolving a binding function:globalThis[name]wasmScope[name]wasmScope["_CPP_" + name]wasmScopekey that starts with__sklib_and matches the target nameThis mirrors how the underlying SplashKit bindings are actually exposed across the different generated/module scopes, rather than assuming a single fixed pattern.
Testing
__sklib_prefix and via the iframe-scopedwasmScope) to confirm the fallback resolves them without regressing previously-working lookups.Scope
This PR only touches
CSharpWasmExpo/main.js. No build artifacts or generated files are included.