webAssembly中js传递字符串给c函数样例

WebAssembly编译环境的部署,可以参考官方手册 (附注)

实例

// js传递字符串给c函数方法 hybase@qq.com
hyscoder.prototype.init = function (url, fileSize) {
    this.logger.logInfo("[initHyscoder] url_len=" + url.length + ", url=" + url);
	var urlTmp = intArrayFromString(url).concat(0); // add '\0'
	this.urlBuffer = Module._malloc(urlTmp.length); // 用声明的c函数分配内存
	Module.HEAPU8.set(urlTmp, this.urlBuffer); //复制url内容
    var ret = Module._initHyscoder(this.urlBuffer, fileSize, this.LogLevel);
    if (0 == ret) {
        this.logger.logInfo("[initHyscoder] success");
    }
    Module._free(this.urlBuffer); // 用声明的c函数释放内存
};

附注:

官方网站
----------------------------------------------------------
https://emscripten.org/docs/getting_started/downloads.html

step 1
Windows
Install Python 3.6 or newer (older versions may not work due to a GitHub change with SSL).
Instead of running emscripten on Windows directly, you can use the Windows Subsystem for Linux to run it in a Linux environment.
----------------------------------------------------------
# Download and install the latest SDK tools.
emsdk install latest

# Make the "latest" SDK "active" for the current user. (writes .emscripten file)
emsdk activate latest (仅仅当前shell可用)

# Activate PATH and other environment variables in the current terminal
emsdk_env.bat (仅仅当前shell可用)

环境变量PATH中手动添加(按实际安装目录设置) 
  D:\software\emsdk-master
  D:\software\emsdk-master\upstream\emscripten
  D:\software\emsdk-master\node\14.15.5_64bit\bin

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值