<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<input type="button" value="Add" onclick="callAdd()" />
<script>
function callAdd() {
const result = Module.ccall('Add',
'number',
['number', 'number'],
[1, 2]);
console.log(`Result: ${result}`);
}
</script>
<script src="js_plumbing.js"></script>
</body>
</html>
According to the emscripten documentation: https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html#calling-compiled-c-functions-from-javascript-using-ccall-cwrap we can use ccall and cwrap functions
This is the Result.vue file:
<template>
<div>
<p button @click="callAdd">Add!</p>
<p>Result: {{ result }}</p>
</div>
</template>
<script>
import * as js_plumbing from './js_plumbing'
export default {
data () {
return {
result: null
}
},
methods: {
callAdd() {
const result = js_plumbing.Module.ccall('Add',
'number',
['number', 'number'],
[1, 2]);
console.log('Result: ${result}');
console.log(result);
}
}
}
</script>
But when executing npm run dev
npm run dev
> mypr...@1.0.0 dev /home/marco/cpp/WebAssemblyinAction/Appendix_B/B.1_ccall/startingV
> cross-env NODE_ENV=development webpack-dev-server --open --hot
I get this error: Cannot read property 'ccall' of undefined"
How to solve it?
Looking forward to your kind help.
Marco
--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/650b07f7-efc8-4132-94de-e556320b01ed%40googlegroups.com.
Weird, it seems the Module object does not get exported. Sorry it seems vue.js related and I know nothing about it.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/650b07f7-efc8-4132-94de-e556320b01ed%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/2b7fb9b9-7d4e-42e5-ac66-f9539b920fd6%40googlegroups.com.
If I were you I'd try to load a handmade js file with vuejs, before trying this. Maybe something is missing in your vuejs setup?
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/650b07f7-efc8-4132-94de-e556320b01ed%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/650b07f7-efc8-4132-94de-e556320b01ed%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/2b7fb9b9-7d4e-42e5-ac66-f9539b920fd6%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/6c34513a-d675-46c0-b39c-f87891115b28%40googlegroups.com.
Sorry I mean you need to be able to import the Module object into your vuejs environment.
On Sat, Dec 28, 2019, 15:10 Mehdi Sabwat <mehdi...@gmail.com> wrote:
I see you also posted there, but yeah ccall is a Module object method. So you need to be able to export a module from vuejs.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/650b07f7-efc8-4132-94de-e556320b01ed%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/2b7fb9b9-7d4e-42e5-ac66-f9539b920fd6%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
ccall in a place it sees, like code in a --pre-js
or --post-js, it will just work. If you use it in a place the compiler
didn’t see, like another script tag on the HTML or in the JS console like
we did in this tutorial, then because of optimizations
and minification you should export ccall from the runtime, using
EXTRA_EXPORTED_RUNTIME_METHODS, for example using
-s 'EXTRA_EXPORTED_RUNTIME_METHODS=["ccall", "cwrap"]',
and call it on Module (which contains
everything exported, in a safe way that is not influenced by minification
or optimizations).
emcc add.c -o js_plumbing.js -s MODULARIZE=1<template>
<div>
<p button @click="callAdd">Add!</p>
<p>Result: {{ result }}</p>
</div>
</template>
<script>
import Module from './js_plumbing'
export default {
data () {
return {
result: null
}
},
methods: {
callAdd() {
const instance = Module({
onRuntimeInitialized() {
console.log(instance._Add(1,2));
this.result = instance._Add(1,2);
}
})
}
}
}
</script>
--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/71327de2-b015-46b4-b554-2bcd215b2f12%40googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAFegzBSGjv07ujUtaZKbpgh9YsJiLnX%2ByNKdyFagcXbwJtX6gg%40mail.gmail.com.