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

How use wasm code without import external file #1048

Open
Gurigraphics opened this issue Jun 10, 2017 · 0 comments
Open

How use wasm code without import external file #1048

Gurigraphics opened this issue Jun 10, 2017 · 0 comments

Comments

@Gurigraphics
Copy link

1- How use this wasm code without import external file ('test.wasm')?

var test = `0061 736d 0100 0000 0186 8080 8000 0160
017f 017f 0382 8080 8000 0100 0484 8080
8000 0170 0000 0583 8080 8000 0100 0106
8180 8080 0000 079e 8080 8000 0206 6d65
6d6f 7279 0200 115f 5a31 3274 6573 7446
756e 6374 696f 6e69 0000 0a8d 8080 8000
0187 8080 8000 0020 0041 0a6a 0b`;

2- How to pass parameters to an imported function out of fetch?

var importObject = {
  imports: {
    _Z12testFunctioni: function(arg) {
      console.log(arg);
    }
  }
};

fetch('test.wasm').then(function(response) {
  response.arrayBuffer().then(function(bytes) {
    WebAssembly.instantiate(bytes, importObject).then(function(obj) {
    	 obj.instance.exports._Z12testFunctioni(num)       
    })
  })
});

console.log( _Z12testFunctioni(10) )

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

1 participant