#include
#include
#include
#include
#include
#include
//#include
using namespace emscripten;//EMSCRIPTEN_BINDINGS 中的 function
using namespace std;
// 注意extern “C” 中的C要大写
extern "C" int EMSCRIPTEN_KEEPALIVE myFunction(int argc, char **argv)
{
cout<<"这是一个测试函数"<
}
extern "C" char* EMSCRIPTEN_KEEPALIVE outName(char *n)
{
char xhName[] = "xuanhun";
strcat(n, xhName);
cout<<"outName = "<
}
// 在浏览器控制台 可以执行 Module._myFunction() 函数,注意是extern "C"
// 函数名只会在前面加一个下划线,否则名称就比较繁琐
// main函数也是默认导出的函数 可以使用 Module._main() 来执行
EM_JS(void, call_alert, (), {
alert('hello world!');
console.log("EM_JS,nihao!");
//throw 'all done';
});
EM_JS(int, call_add, (int a,int b), {
console.log("EM_JS,add!");
return a + b;
});
//Null-terminated C strings can also be passed into EM_JS functions,
//but to operate on them, they need to be copied out from the heap to convert to high-level JavaScript strings.
// use connsole.log('hello ' + UTF8ToString(str));
EM_JS(char*, call_add_string, (char* a,char* b), {
console.log("EM_JS,add_string!");
console.log(UTF8ToString(a));
var s = "hello,jsStr";
//return a;//也可以
var returnStr = "Hello C#!";
var bufferS