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

本文介绍了一个具体的WebAssembly应用实例,展示了如何通过JavaScript调用C语言函数,并实现字符串参数的传递。此外,还提供了详细的Windows环境下WebAssembly编译环境搭建步骤。
1853

被折叠的 条评论
为什么被折叠?



