Skip to content

Commit 25360be

Browse files
authored
Document embind array field requiring registration of std::array emscripten-core#4510 (emscripten-core#11834)
emscripten-core#4510 Added support for raw array fields by interpreting them as a std::array. However, while mentioned in the pull request, it was not documented that you still have to register the std::array type.
1 parent 4a2c7a2 commit 25360be

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

  • site/source/docs/porting/connecting_cpp_and_javascript

site/source/docs/porting/connecting_cpp_and_javascript/embind.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ Consider the example below:
205205
int age;
206206
};
207207
208+
// Array fields are treated as if they were std::array<type,size>
209+
struct ArrayInStruct {
210+
int field[2];
211+
};
212+
208213
PersonRecord findPersonAtLocation(Point2f);
209214
210215
EMSCRIPTEN_BINDINGS(my_value_example) {
@@ -218,6 +223,16 @@ Consider the example below:
218223
.field("age", &PersonRecord::age)
219224
;
220225
226+
value_object<ArrayInStruct>("ArrayInStruct")
227+
.field("field", &ArrayInStruct::field) // Need to register the array type
228+
;
229+
230+
// Register std::array<int, 2> because ArrayInStruct::field is interpreted as such
231+
value_array<std::array<int, 2>>("array_int_2")
232+
.element(index<0>())
233+
.element(index<1>())
234+
;
235+
221236
function("findPersonAtLocation", &findPersonAtLocation);
222237
}
223238

0 commit comments

Comments
 (0)