HOLA MUNDO
- Descargar SDK Emscripten haciendo uso de este link: https://emscripten.org/docs/getting_started/downloads.html
- Crear archivo “hello.c” con el siguiente código:
#include <stdio.h>
int main(int argc, char ** argv) {
printf(«Hola mundo\n»);
}
- En el mismo directorio que “hello.c”, correr en línea de comando: emcc hello.c -s WASM=1 -o hello.html.
- Abrir “hello.html” en el navegador de su preferencia.
FUNCIÓN PERSONALIZADA
- Crear archivo “hello2.c” en un nuevo directorio y pegar este código:
#include <stdio.h>
#include <emscripten/emscripten.h>
int main(int argc, char ** argv) {
printf(«Hello World\n»);
}
#ifdef __cplusplus
extern «C» {
#endif
EMSCRIPTEN_KEEPALIVE void myFunction(int argc, char ** argv) {
printf(«MyFunction Called\n»);
}
#ifdef __cplusplus
}
#endif
- Agregar archivo “html_template/shell_minimal.html” al directorio.
- Correr en línea de comando: emcc -o hello3.html hello3.c -O3 -s WASM=1 –shell-file html_template/shell_minimal.html -s NO_EXIT_RUNTIME=1 -s «EXTRA_EXPORTED_RUNTIME_METHODS=[‘ccall’]»
- Abrir “hello2.html” y agregar:
<button class=»mybutton»>Run myFunction</button>
- Al final del elemento <script>, agregar el siguiente código:
document.querySelector(‘.mybutton’)
.addEventListener(‘click’, function() {
alert(‘check console’);
var result = Module.ccall(
‘myFunction’, // name of C function
null, // return type
null, // argument types
null // arguments
); });