emscripten

Providing stdin to an emscripten HTML program?

℡╲_俬逩灬. 提交于 2019-11-30 13:45:47
I have a C program that takes one argument (a char array / string) via command line and also reads from stdin. I've compiled it to JavaScript using emscripten. This was successful and I can run it just like the normal C program using node.js: emcc -O2 translate.c node translate.js "foo" < bar.txt As you can see, I'm providing the string "foo" as an argument and the contents of bar.txt as stdin. Now I want this to be a self-contained HTML file. By changing the output to HTML: emcc -O2 translate.c -o trans.html I provide the argument by adding arguments: ['foo'], to the definitions in var Module

Pass a JavaScript array as argument to a WebAssembly function

江枫思渺然 提交于 2019-11-30 10:41:20
问题 I would like to test WebAssembly for doing some complex array calculations. So I've written a simple C++ function adding two int arrays containing 3 elements each : // hello.cpp extern "C" { void array_add(int * summed, int* a, int* b) { for (int i=0; i < 3; i++) { summed[i] = a[i] + b[i]; } } } And compiled this with : emcc hello.cpp -s WASM=1 -s "MODULARIZE=1" -s "EXPORT_NAME='HELLO'" -s "BINARYEN_METHOD='native-wasm'" -s "EXPORTED_FUNCTIONS=['_array_add']" -o build/hello.js Which generates

Interaction with C++ classes in Emscripten

别来无恙 提交于 2019-11-30 06:58:00
The Emscripten tutorial give a good explanation of how to interact with C functions: https://github.com/kripken/emscripten/wiki/Interacting-with-code But how do you interact with C++ classes: Call a constructor to create an object Delete an obj Prevent dead code elimination of classes and its methods Zardoz89 Check this : http://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_and_javascript/embind.html Example : C++ code : #include <emscripten/bind.h> using namespace emscripten; class MyClass { public: MyClass(int x, std::string y) : x(x) , y(y) {} void incrementX() { ++x; } int

Passing JS function to Emscripten-generated code

我与影子孤独终老i 提交于 2019-11-30 06:38:06
I have a piece of C++ code converted to JavaScript via Emscripten. I would like the converted C++ code to call back to the JavaScript code that calls it. Something like: JavaScript: function callback(message) { alert(message); } ccall("my_c_function", ..., callback); C++: void my_c_function(whatever_type_t *callback) { callback("Hello World!"); } Is this possible somehow? Daniel Baulig I believe the accepted answer is a bit outdated. Please refer to this bullet point in the "Interacting with code" emscripten tutorial . E.g. C: void invoke_function_pointer(void(*f)(void)) { (*f)(); } JS: var

Pass a JavaScript array as argument to a WebAssembly function

空扰寡人 提交于 2019-11-29 22:38:06
I would like to test WebAssembly for doing some complex array calculations. So I've written a simple C++ function adding two int arrays containing 3 elements each : // hello.cpp extern "C" { void array_add(int * summed, int* a, int* b) { for (int i=0; i < 3; i++) { summed[i] = a[i] + b[i]; } } } And compiled this with : emcc hello.cpp -s WASM=1 -s "MODULARIZE=1" -s "EXPORT_NAME='HELLO'" -s "BINARYEN_METHOD='native-wasm'" -s "EXPORTED_FUNCTIONS=['_array_add']" -o build/hello.js Which generates among others, a js and a wasm file. I load these with the following html page : <!doctype html> <html

Use Emscripten with Fortran: LAPACK binding

巧了我就是萌 提交于 2019-11-29 21:27:12
问题 My goal is to use LAPACK with Emscripten. My question is: how to port LAPACK to JS? The are two ways I can think of: CLAPACK to JS where my question is: does anybody know an unofficial version that is later than 3.2.1? And the other way to think of is: how to port FORTRAN to JS? Emscripten is capable of transforming C code to JavaScript. But unfortunately, LAPACK 3.5.0 (http://www.netlib.org/lapack/) is only available in FORTRAN95. The CLAPACK project (http://www.netlib.org/clapack/) is

Providing stdin to an emscripten HTML program?

孤者浪人 提交于 2019-11-29 18:12:44
问题 I have a C program that takes one argument (a char array / string) via command line and also reads from stdin. I've compiled it to JavaScript using emscripten. This was successful and I can run it just like the normal C program using node.js: emcc -O2 translate.c node translate.js "foo" < bar.txt As you can see, I'm providing the string "foo" as an argument and the contents of bar.txt as stdin. Now I want this to be a self-contained HTML file. By changing the output to HTML: emcc -O2

Interaction with C++ classes in Emscripten

 ̄綄美尐妖づ 提交于 2019-11-29 07:07:46
问题 The Emscripten tutorial give a good explanation of how to interact with C functions: https://github.com/kripken/emscripten/wiki/Interacting-with-code But how do you interact with C++ classes: Call a constructor to create an object Delete an obj Prevent dead code elimination of classes and its methods 回答1: Check this : http://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_and_javascript/embind.html Example : C++ code : #include <emscripten/bind.h> using namespace emscripten;

Passing JS function to Emscripten-generated code

旧时模样 提交于 2019-11-29 06:14:50
问题 I have a piece of C++ code converted to JavaScript via Emscripten. I would like the converted C++ code to call back to the JavaScript code that calls it. Something like: JavaScript: function callback(message) { alert(message); } ccall("my_c_function", ..., callback); C++: void my_c_function(whatever_type_t *callback) { callback("Hello World!"); } Is this possible somehow? 回答1: I believe the accepted answer is a bit outdated. Please refer to this bullet point in the "Interacting with code"

Using libraries with emscripten

旧城冷巷雨未停 提交于 2019-11-29 05:07:11
I have just started using Emscripten and would like to start using GLFW and other libraries. I am completely lost on how to build, link, and use other libraries with Emscripten. I have tried following the instructions on the Emscripten site but have they haven't helped me any. http://kripken.github.io/emscripten-site/docs/compiling/Building-Projects.html#using-libraries Is there any place with detailed instructions on how to use libraries with Emscripten? Or specifically GLFW? Emscripten provide itself very few libraries. Those libraries are the minimum to get some OperativeSystem