Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow adding meta data #26

Open
kenchris opened this issue Jan 27, 2021 · 1 comment
Open

Allow adding meta data #26

kenchris opened this issue Jan 27, 2021 · 1 comment

Comments

@kenchris
Copy link

kenchris commented Jan 27, 2021

In response to w3ctag/design-reviews#532

function print(...args) {
  for (let x of args) console.log(x + "\n")
}

let table = new Table({element: "anyfunc", minimum: 10});

let print_i32 = new WebAssembly.Function({parameters: ["i32"], results: []}, print);
table.set(0, print_i32);
let print_f64 = new WebAssembly.Function({parameters: ["f64"], results: []}, print);
table.set(1, print_f64);
let print_i32_i32 = new WebAssembly.Function({parameters: ["i32", "i32"], results: []}, print);
table.set(2, print_i32_i32);

In the above example where you are exporting a JS function to Wasm, wouldn't it makes sense it I could supply meta data (in the WebAssembly.Function call) that would be given to the print method when run, so that I could change the formatting.

@SPY
Copy link
Collaborator

SPY commented Oct 19, 2023

I believe we don't need a special machinery for this use case. Regular JS bind will be enough here.

let print_i32 = new WebAssembly.Function({parameters: ["i32"], results: []}, print.bind('i32'));
table.set(0, print_i32);
let print_f64 = new WebAssembly.Function({parameters: ["f64"], results: []}, print.bind('i64'));
table.set(1, print_f64);

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

No branches or pull requests

2 participants