-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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 to call a webassembly method in vue.js? #10114
Comments
Testing this on my side, the issue appears to be that an error gets thrown when compiling the module due to the ENVIRONMENT flag. If you change the command line to the following, the module is generated and the web page runs:
|
Hi @cggallant Gerard!
Now I’m facing this problem: “Cannot read property ‘ccall’ of undefined” : But I compiled the add.c file, creating js_plumbing.js and js_plumbing.wasm files, with this command, which exports the methods ‘ccall’ and ‘cwrap’ : emcc add.c -o js_plumbing.js -s EXTRA_EXPORTED_RUNTIME_METHODS=[‘ccall’,‘cwrap’] -s ENVIRONMENT=‘web’,‘worker’ |
In order to import the Emscripten code like an ES6 module, you'll need to compile the module with the Because the Modularize flag is used, you'll need to create an instance of the Module object before you can call into the module (it doesn't get downloaded and instantiated until you create an instance of the object):
|
I "solved" through a sort of an hack, which I do not like at all. This is the Result.vue file:
which is exactly the same as the one used before, as you can see. The only thing I've done to make it working, is to add export to the definition of Module in js_plumbing.js : js_plumbing.js
But, as I said, I do not like this hack. |
@cggallant Gerard I'm trying to you use your elegant solution, but I'm encountering some problems. I complied add.c , as you suggested, in this way:
Then, I modified Result.vue as follows:
But I'm getting this error message:
Aside from this error message, I do not understand what myModule should be in
|
I haven't used Vue before so I'm not sure where you'd place the variable but you only want to create an instance of the Module object, that was imported from the js_plumbing.js file, the once because it's creating a new instance of the WebAssembly module each time you do I called it I'll see if I can get Vue going on my system to see if I can help you out better. Might be a few hours though, my brother and his family just arrived in town. |
very kind of you @cggallant Gerard, thank you very much. Much appreciated. var Module = (function() { |
Update (Dec 30, 2019): I was able to get this working. I've updated the following with my results. There's a In my
In my controller, I check to see if $myModule is null and, if so, the module is loaded:
This might be because I'm running on a Windows machine, Visual Studio, and just the development web server but, to get the content-type to work, I needed to adjust my
|
I'm not sure that enclosing the Vue instance within the Module in main.js has no side-effects, since the vue instance created in main.js has global coverage on the entire webapp, not just the part related to wasm |
It's now working on my machine. I've updated my comment above. |
Hi @cggallant Gerard! I compiled add.c in this way:
And, thanks to @anthumchris , I modified Result.vue as follows: Result.vue :
|
@cggallant Gerard your solution works fine with Ubuntu 18.04.02 without needing to modify vue.config.js . Thank you very much for your kind help!!! I do not understand why in Result.vue we need to create a hook beforeCreate() to check if $myModule is null and, if so, to load the module.
And got this error message: Cannot read property 'ccall' of null but I do not understand this requirement |
My thought was that, rather than download and instantiate the module in main.js (when the app first loads), the first component that needs it creates it. Once instantiated, the module is available to all components that need it. Rather than having a global object, the following worked for me, where the component uses a local variable for the module instance:
|
Now I do understand... thank you very much Gerard! |
@marcoippolito @cggallant Where do you place the wasm file? Is there a way to config its path in vue? |
Follows the advice from @cggallant in emscripten-core/emscripten#10114 Note that this will require coordinate changes in the consumer of the library Check this diff of bls_c.js to see the impact of this flag https://www.diffchecker.com/nLKh3P65
This works for me. Thanks. |
I'm trying to transpose to vue.js this simple html page add.html:
which calls the Add function defined in add.c :
and converted to js_plumbing and js_plumbling.wasm files through the command:
In console of google chrome I get these errors:
Where in js_plumbing_js :
In Google Chrome: createWasm @ js_plumbing.js?2b2c:1680
line 1680 of js_plumbing.js:
in Google Chrome: eval @ js_plumbing.js?2b2c:1930
line 1930 of js_plumbing.js:
And many other errors related to wasm :
https://drive.google.com/open?id=1-aY2Iae1BRPjiLsslQ9P5khUKzuVZJLm
https://drive.google.com/open?id=1tlhlp38XNXUp61Vc0pZagz8hWN9eCKpb
So... how should I modify the callAdd() method in Result.vue in order to correctly execute the Add function in js_plumbing.js and in js_plumbing.wasm files?
The text was updated successfully, but these errors were encountered: