从emscripten访问struct字段 [英] Accessing struct fields from emscripten
本文介绍了从emscripten访问struct字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出以下代码:
typedef struct {
int foo;
} Bar;
Bar test() { Bar result = { .foo = 2 }; return result; }
并假设 test()
可以可以从JavaScript访问,如何将结构转换为JavaScript对象或以其他方式能够使用返回值,以便(在JavaScript中) myJavascriptObject.foo == 2
将返回true?
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?
推荐答案
一种解决方法是在java中执行操作:
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.
这篇关于从emscripten访问struct字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文