Skip to content

ZhiguoZh/WebAssemblyNodeJSSample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

WebAssemblyNodeJSSample

Compile a simple C code and execute in Node.js

Preliminary

On my machine, I have emcc and Node.js installed as a preparation of this project. I list the version information for your reference:

  • Node.js v8.9.1
  • emcc 1.38.11

Compile

To compile the source code, we should firstly set the environment for emsdk:

$ source path/to/emsdk/emsdk_env.sh

Thus, makefile could find the toolchain. Then, we run:

$ make

The resultant files are addTwo.js and addTwo.wasm.

Execution

In node, we firstly load the js file and call the addTwo function, it's to be noted that exported functions' names begin with an underscore:

> w=require('./addTwo.js')
> w._addTwo(12,222)
234

About

Compile a simple C code and execute in Node.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published