emscripten

Emscripten Bindings: How to create an accessible C/C++ array from Javascript?

…衆ロ難τιáo~ 提交于 2019-12-24 00:34:47
问题 I am using box2d and attempting to create a chain shape. In order to create a chain shape or polygon shape I must pass an array of vectors in order to specify the geometry. I do not see any documentation to help me accomplish this, and the notes about bindings here don't go into any detail about arrays. How can I construct an array? 回答1: I have solved this problem by using these (as yet undocumented) emscripten features. Note that I am accessing the functions and values (like ALLOC_STACK and

Linking OpenSSL with webassembly

最后都变了- 提交于 2019-12-23 21:27:47
问题 Linking OpenSSL to webassembly Before asking this question I just want to say that I did some homework. The question is very similar to the one already asked here i.e. How to link OpenSSL with emscripten? After I found a very good and detail manual how to compile OpenSSL to webassemly here https://www.ip6.li/node/129 I was able to run all steps successfully i.e. 1) first go to the directory where the latest emscripten is downloaded and set some path variables: ~/emscripten/emsdk$ source .

Accessing struct fields from emscripten

大兔子大兔子 提交于 2019-12-23 18:56:07
问题 Given the following code: typedef struct { int foo; } Bar; Bar test() { Bar result = { .foo = 2 }; return result; } and assuming that test() can be accessed from JavaScript, how would I convert the struct to a JavaScript object or otherwise be able to use the return value such that (in JavaScript) myJavascriptObject.foo == 2 will return true? 回答1: One workaround is doing things as in java: Bar createBar(int foo) { Bar result = { .foo = foo }; return result; } int getFoo(Bar in) { return in

How to pass strings between C++ and javascript via emscripten

跟風遠走 提交于 2019-12-23 09:04:22
问题 I am learning emscripten, and I can't even get the most basic string manipulation working, when passing strings between C++ and JS. For example, I would like to write a string length function. In C++: extern "C" int stringLen(std::string p) { return p.length(); } Called from javascript as: var len = _stringLen("hi."); This yields 0 for me. How do I make this work as expected? Which string type should I use here? char const* ? std::wstring ? std::string ? None seem to work; I always get pretty

How to use Emscripten compiled JavaScript within React / React Native

一笑奈何 提交于 2019-12-21 05:06:37
问题 I'm currently using Emscripten to compile a basic C function into JavaScript to use within a React Native project. However, when I import Module from inside React code, the Module object is empty. This occurs in both React and React Native projects. Running index.js in my terminal with node ./index.js returns the expected result. I'm compiling ping.c and outputting ping.js with this command: emcc ping.c -o ping.js -s WASM=0 -s EXPORTED_FUNCTIONS='["_pingIt"]' ping.c: #include <stdio.h>

How do I read a user-specified file in an emscripten compiled library?

一世执手 提交于 2019-12-19 17:35:44
问题 I'm currently working on a file parsing library in C with emscripten compile support. It takes a file path from the user where it reads the binary file and parses it. I understand that emscripten doesn't support direct loading of files, but instead uses a virtual filesystem. Is there any way to load the file at the given path into the virtual filesystem so that the emscripten compiled C lib can read it? I'm looking for solutions for both NodeJS and in the browser. 回答1: If you want compile

How do I read a user-specified file in an emscripten compiled library?

♀尐吖头ヾ 提交于 2019-12-19 17:34:05
问题 I'm currently working on a file parsing library in C with emscripten compile support. It takes a file path from the user where it reads the binary file and parses it. I understand that emscripten doesn't support direct loading of files, but instead uses a virtual filesystem. Is there any way to load the file at the given path into the virtual filesystem so that the emscripten compiled C lib can read it? I'm looking for solutions for both NodeJS and in the browser. 回答1: If you want compile

Can I read files from the disk by using Webassembly?

馋奶兔 提交于 2019-12-18 14:15:02
问题 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 calculation (10 * 20) after reading the file. emcc compiled the file just fine, no errors. But when I serve the file over HTTP by running emrun, it cannot open the file. This is what I see in the emrun web console: Unable to open file 200 Is there

Emscripten - cmake - pass emscripten options in CMakeList file

僤鯓⒐⒋嵵緔 提交于 2019-12-18 13:28:43
问题 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 / normal desktop) with the following CMakeList.txt file cmake_minimum_required(VERSION 3.7) project(Engine) set(CMAKE_CXX_STANDARD 11) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake") set(CMAKE_INCLUDE_PATH /usr/local/include)

emscripten: Memory leak with std::vector & std::map in c++ code

眉间皱痕 提交于 2019-12-13 16:16:05
问题 I want to know how to properly delete the memory of std::vector & std:: map allocated in c++ code. I am sharing my code here # include <vector> # include <stdio.h> # include <stdlib.h> //realloc # include <math.h> # include <map> # include <unordered_map> #include <emscripten/bind.h> using namespace emscripten; struct Edge{ // Coordinates of two vertices float c[6]; float normal[3]; int i1, i2; Edge() {}; Edge(const float * v1, const float * v2, const float * _normal, int _i1, int _i2) { i1 =