-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
35 lines (29 loc) · 1.15 KB
/
script.js
File metadata and controls
35 lines (29 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Assuming you have a function to load the C WebAssembly module (check your environment/tools for specifics)
async function loadCModule() {
const response = await fetch('my_c_module.wasm');
const buffer = await response.arrayBuffer();
return await WebAssembly.compile(buffer);
}
import * as dartProgram from './main.dart.mjs';
async function callCFunctionFromJS(value1, value2) {
// Load the C module
const cModule = await loadCModule();
const imports = {
// Provide the C module instance here
'my_c_module': {
add: cModule.exports.add, // Assuming 'add' is the exported function from C
},
};
const module = await dartProgram.instantiate(
WebAssembly.compileStreaming(fetch('main.dart.wasm')),
imports
);
const result = module.exports.myDartFunction(value1, value2);
document.getElementById('output-paragraph').textContent = result;
}
// Event listener remains the same
document.getElementById('call-button').addEventListener('click', () => {
const inputValue1 = document.getElementById('input1').value;
const inputValue2 = document.getElementById('input2').value;
callCFunctionFromJS(inputValue1, inputValue2);
});