Skip to content

feature request: pass arbitrary functions (not just exports) from AS to JS, or vice versa.Β #64

@trusktr

Description

@trusktr

Use case:

We want to make, for example, a requestAnimationFrame function and pass that into Wasm via the imports object.

The AssemblyScript user should be able to dynamically create and pass any callback to this function.

So on the JavaScript side, it would be something like:

const imports = {
  requestAnimationFrame(assemblyscriptFunction) {
    // call assemblyscriptFunction at some point, f.e.
    requestAnimationFrame(assemblyscriptFunction)
  }
}

Problem is, at the moment, assemblyscriptFunction is an AssemblyScript pointer number. So the above won't work.

I'm not sure how to get a function using its pointer and call it, but once we know how to do that, then we can abstract it in as-bind.


Similarly, although maybe less useful, we should be able to pass JS functions into an AS function going the other way.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions