Diseña un sitio como este con WordPress.com
Comenzar

WASM & C

HOLA MUNDO

  1. Descargar SDK Emscripten haciendo uso de este link: https://emscripten.org/docs/getting_started/downloads.html
  2. Crear archivo “hello.c” con el siguiente código:

#include <stdio.h>

int main(int argc, char ** argv) {

    printf(«Hola mundo\n»);

}

  1. En el mismo directorio que “hello.c”, correr en línea de comando: emcc hello.c -s WASM=1 -o hello.html.
  2. Abrir “hello.html” en el navegador de su preferencia.

FUNCIÓN PERSONALIZADA

  1. 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

  1. Agregar archivo “html_template/shell_minimal.html” al directorio.
  2. 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’]»
  3. Abrir “hello2.html” y agregar: 

<button class=»mybutton»>Run myFunction</button>

  1. 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

        );    });

Anuncio publicitario

Deja una respuesta

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Salir /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Salir /  Cambiar )

Conectando a %s

A %d blogueros les gusta esto: