I'm trying to do some library testing using emscripten and c++. I need to make some JavaScript variables persist between c++ calls, but I haven't been able to figure out how to do it.
I figure it's either something simple that I'm missing, or it just isn't possible. This is a standalone program with nothing else running. The following is a minimal example:
#include <emscripten.h>
int main() {
//this works and prints 1
EM_ASM(
var x = 1;
console.log(x);
);
//this throws an error 'x is not defined'
EM_ASM(
console.log(x);
);
return 0;
}
I compile and run the code using the following commands:
emcc main.cpp
node a.out.js
The output is correct for the first call, but the second call throws a not defined error. I need some way to keep this variable in scope between calls so I can use it.
Any help? Thanks.