Questions tagged [emscripten]

Emscripten is an LLVM-to-JavaScript compiler. It takes LLVM bitcode - which can be generated from C/C++, using llvm-gcc or clang, or any other language that can be converted into LLVM - and compiles that into JavaScript, which can be run on the web (or anywhere else JavaScript can run).

Links to demos, tutorial, FAQ, etc: https://github.com/kripken/emscripten/wiki

Main project page: http://emscripten.org

1241 questions
128
votes
5 answers

Compiling Python to WebAssembly

I have read that it is possible to convert Python 2.7 code to Web Assembly, but I cannot find a definitive guide on how to to so. So far I have compiled a C program to Web Assembly using Emscripten and all its necessary components, so I know it is…
Robbie
  • 1,733
  • 2
  • 13
  • 20
44
votes
2 answers

How to handle passing/returning array pointers to emscripten compiled code?

From a windows 7 environment, I've used emcc to compile a simple c program which accepts an array and modifies it (see below). double* displayArray(double *doubleVector) { for (int cnt = 0; cnt < 3; cnt++) printf("doubleVector[%d] =…
user2618901
  • 441
  • 1
  • 4
  • 3
39
votes
6 answers

Using Boost with Emscripten

I have a c++ project I would like to convert to a web application. For this purpose, I would like to use Emscripten to build the project. The project uses some external libraries. I managed to compile or find the JavaScript version of most libraries…
Julien
  • 2,139
  • 1
  • 19
  • 32
30
votes
2 answers

Can I read files from the disk by using Webassembly?

I followed the Webassembly getting started tutorial http://webassembly.org/getting-started/developers-guide/ It worked fine and displayed the "Hello, world!" message in the browser. Then I tried a small C++ code, that opens a text file and does the…
Thiago Silvino
  • 411
  • 1
  • 4
  • 5
30
votes
5 answers

Can I somehow build webassembly code *without* the emscripten "glue"?

Can I somehow create a wasm file, that will work on its own as described in MDN here (by instatiating the objects and calling functions on them)? All the guides I can find (such as this one on MDN) recommend using emscripten; that will, however,…
Karel Bílek
  • 36,467
  • 31
  • 94
  • 149
27
votes
2 answers

Pass a JavaScript array as argument to a WebAssembly function

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…
sebpiq
  • 7,540
  • 9
  • 52
  • 69
24
votes
1 answer

Passing a JS ArrayBuffer or TypedArray to Emscripten w/o Copying

I have a very large ArrayBuffer (or TypedArray) in JavaScript that I want to pass to an emscriptened function. I'd like to pass the raw bytes without incurring a copy. If my C/C++ function takes an std::string as in: void processBuffer(std::string…
Adi Shavit
  • 16,743
  • 5
  • 67
  • 137
22
votes
3 answers

Emscripten - C++ with pure html5 canvas support (not WebGL)

Is there any way of accessing canvas 2D context under C++ when using emscripten? I'd like to be able to draw simple shapes/paths using canvas' api functions like lineTo, fillRect1d done, etc. (so basically use any of the functions listed here. I…
Konrad Madej
  • 1,271
  • 1
  • 11
  • 19
21
votes
5 answers

Passing JS function to Emscripten-generated code

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) { …
Lóránt Pintér
  • 10,152
  • 14
  • 47
  • 53
20
votes
2 answers

Interaction with C++ classes in Emscripten

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…
Mortennobel
  • 3,383
  • 4
  • 29
  • 46
19
votes
3 answers

Is it possible to submit HTTP requests with WebAssembly?

I'm trying to submit a simple HTTP GET request in WebAssembly. For this purpose, I wrote this program (copied from Emscripten site with slight modifications): #include #include #ifdef __EMSCRIPTEN__ #include…
Glory to Russia
  • 17,289
  • 56
  • 182
  • 325
19
votes
2 answers

Emscripten - cmake - pass emscripten options in CMakeList file

How to use emcmake cmake and pass emscripten command-line options? Pretty new to c++ / CMake, but can't find anything helpful on google. So maybe the question is just to stupid, in that case I apologise. I can build my project (non-webassembly /…
DutchKevv
  • 1,659
  • 2
  • 22
  • 39
18
votes
3 answers

How to access WebAssembly linear memory from C/C++

I'm writing a small C program intended to be compiled to wasm w/ emcc and run in a web browser. Because wasm exported functions can only accept simple number values as parameter inputs and return values, I need to share memory between the JavaScript…
Brannon
  • 1,286
  • 2
  • 21
  • 36
17
votes
1 answer

How a WebAssembly application maps its native Window / OpenGL / Vulkan calls to a canvas element in DOM?

I'm reading about WebAssembly, and I was curious about how to port graphics programming like Vulkan or OpenGL to a canvas element. The documentation is long, and I think I'll figure this out eventually, but I was curious and not successful in…
Rafael Beckel
  • 2,199
  • 5
  • 25
  • 36
17
votes
4 answers

How to redirect/render Pyodide output in browser?

I have recently come across the Pyodide project. I have built a little demo using Pyodide, but although I've spent a lot of time looking at the source, it is not obvious (yet) to me how to redirect print output from python (other than modifying the…
Homunculus Reticulli
  • 65,167
  • 81
  • 216
  • 341
1
2 3
82 83