• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

javascript和C++交互wasmemscripten

武飞扬头像
编程经验随笔
帮助1

#include <emscripten.h>
#include <emscripten/bind.h>//EMSCRIPTEN_BINDINGS 的头文件
#include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
//#include <SDL.h>
using namespace emscripten;//EMSCRIPTEN_BINDINGS 中的 function
using namespace std;
// 注意extern “C” 中的C要大写
extern "C" int EMSCRIPTEN_KEEPALIVE myFunction(int argc, char **argv)
{
    cout<<"这是一个测试函数"<<endl;
    return 0;
}

 extern "C" char* EMSCRIPTEN_KEEPALIVE outName(char *n)
 {
    char xhName[] = "xuanhun";
    strcat(n, xhName);
    cout<<"outName = "<<n<<endl;
    return n;
 }

// 在浏览器控制台 可以执行 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

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhfjihka
系列文章
更多 icon
同类精品
更多 icon
继续加载