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.foo; }

Ugly, adds boilerplate, and requires more stuff be exported, but it works.



来源:https://stackoverflow.com/questions/25346367/accessing-struct-fields-from-emscripten

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!