Skip to content

Faraday1987/Webassembly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#Webassembly C with Javascript

##🚀 Start

yarn install

yarn start

emcc lib/demo.c -s WASM=1 -o public/demo.js

Export the html with wasm and js files

emcc lib/demo.c -s WASM=1 -o public/demo.html

Export wasm file alone no extras

emcc lib/demo.c -s WASM=1 -s SIDE_MODULE=1 -o public/demo.wasm

We can improve the compilation optimitation by 3 levels -O1 -O2 -O3

This return very small files in kb O1 low optimitation O3 Hig Optimitation

emcc lib/demo.c -s WASM=1 -O3 -o public/demo.js

Include the javascript files in compilation time at the end

--> this will include in the demo.js output file: --post-js public/ready.js emcc lib/demo.c -s WASM=1 --post-js public/ready.js -O3 -o public/demo.js

Include the javascript files in compilation time at start

--> this will include in the demo.js output file: --pre-js public/ready.js emcc lib/demo.c -s WASM=1 --pre-js public/ready.js -O3 -o public/demo.js

para exportar las funciones de C

int getNumber() {
    return 22
}

Debemos poner explicitamente -s EXPORTED_FUNCTIONS="['_getNumber']" separados por coma las funciones que serán utilizadas en javascript

emcc lib/demo.c -s WASM=1 -s EXPORTED_FUNCTIONS="['_getNumber']" --post-js public/ready.js -O3 -o public/demo.js

Se quita por default el main exportado, pero se agrega manualmente

emcc lib/demo.c -s WASM=1 -s EXPORTED_FUNCTIONS="['_main','_getNumber']" --post-js public/ready.js -O3 -o public/demo.js

Se pueden llamar las funciones desde js especificando nombre y tipo de retorno

ccall('getNumber', 'number')

Pasando parametros

ccall('getNumber', 'number', ['number'], [33])

About

Webassembly Javascript C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published