Support WebAssembly
- Dominant language
- JavaScript
- Stars
- 4
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
[prototype](https://git.sr.ht/~drsensor/nusa-wasm-runtime/tree) (stalled)
> **Warning**: may not relevant anymore
> see comment at the bottom for the current approach
- [ ] #1 (methods, `constructor`, `extern instance`)
- [x] #4
- [ ] #2
- [ ] WTF16<->UTF8 which require either:
- multi-value where some high-level lang struggle to support this, or
- component-model which still in draft
- [ ] #3
- [ ] #9
- [x] #11
- [ ] #27
Unlike Javascript module that export class, setter in WebAssembly doesn't automatically update html attribute. You need to specify which bounded property to update.
```zig
//! lib.zig -> script.wasm
/// update property which bounded to several attributes
extern fn update([]const u8) void; // 👈👇
/// most likely explicit update may not needed since
/// the update are automatic after event handler is executed
/// get instance id number
/// throw error if not an instance (i.e called inside static method)
extern fn lc() u8; // link count
// extern lc: u8 // according to spec, wasm support global value import
var count: [4]u8 = undefined; // limit instance to 4
export fn @"get count"() u8 {
return count[lc()];
}
export fn @"set count"(value: u8) void {
count[lc()] = value;
update("count");
}
export fn constructor() { // called every time when attached into <render-scope>
count[lc()] = 0;
}
export fn static() { // called only once
// do something when the wasm module loaded
}
var static_count: u8 = 0;
export fn @"static get count"() u8 {
return static_count;
}
export fn @"static set count"(value: u8) void {
static_count = value;
update("static count");
}
export fn increment() void {
count[lc()] += 1;
@"set count"(count);
static_count += 1;
@"static set count"(static_count);
}
```
> **Note** that the setter **not** really necessary in this example. You can rid them and just call `update` function. I use setter just for demonstration that this feature indeed support a setter.
```html
<!-- page.html -->
<render-scope>
<button onclick:="increment">
<script type="application/wasm" src="script.wasm">
```
---
> **🤔 Food for Thought**
> Maybe consider storing the property, getter/setter operation, and others as ArrayBuffer for maximum flexibility
> (inspired from [WASM-4 Memory Map](https://wasm4.org/docs/reference/memory))
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.