@@ -2187,17 +2187,17 @@ void SerializeIterToJson_serialize_table(void) {
21872187
21882188 test_str (json , "{\"results\":["
21892189 "{"
2190- "\"ids\":[[\"Position\"], [\"Foo\"], [\"flecs.core.Identifier\",\"flecs.core.Name\"] ], "
2190+ "\"ids\":[[\"Position\"], [\"Foo\"]], "
21912191 "\"entities\":[\"e1\"], "
2192- "\"values\":[[{\"x\":10, \"y\":20}], 0, 0 ]"
2192+ "\"values\":[[{\"x\":10, \"y\":20}], 0]"
21932193 "}, {"
2194- "\"ids\":[[\"Position\"], [\"Velocity\"], [\"Foo\"], [\"Bar\"], [\"flecs.core.Identifier\",\"flecs.core.Name\"] ], "
2194+ "\"ids\":[[\"Position\"], [\"Velocity\"], [\"Foo\"], [\"Bar\"]], "
21952195 "\"entities\":[\"e2\"], "
2196- "\"values\":[[{\"x\":20, \"y\":30}], [{\"x\":1, \"y\":1}], 0, 0, 0 ]"
2196+ "\"values\":[[{\"x\":20, \"y\":30}], [{\"x\":1, \"y\":1}], 0, 0]"
21972197 "}, {"
2198- "\"ids\":[[\"Position\"], [\"Mass\"], [\"flecs.core.Identifier\",\"flecs.core.Name\"] ], "
2198+ "\"ids\":[[\"Position\"], [\"Mass\"]], "
21992199 "\"entities\":[\"e3\"], "
2200- "\"values\":[[{\"x\":30, \"y\":40}], [{\"value\":100}], 0 ]}]"
2200+ "\"values\":[[{\"x\":30, \"y\":40}], [{\"value\":100}]]}]"
22012201 "}" );
22022202
22032203 ecs_os_free (json );
@@ -2275,17 +2275,17 @@ void SerializeIterToJson_serialize_table_w_id_labels(void) {
22752275
22762276 test_str (json , "{\"results\":["
22772277 "{"
2278- "\"id_labels\":[[\"position\"], [\"Foo\"], [\"Identifier\", \"Name\"] ], "
2278+ "\"id_labels\":[[\"position\"], [\"Foo\"]], "
22792279 "\"entities\":[\"e1\"], "
2280- "\"values\":[[{\"x\":10, \"y\":20}], 0, 0 ]"
2280+ "\"values\":[[{\"x\":10, \"y\":20}], 0]"
22812281 "}, {"
2282- "\"id_labels\":[[\"position\"], [\"velocity\"], [\"Foo\"], [\"Bar\"], [\"Identifier\", \"Name\"] ], "
2282+ "\"id_labels\":[[\"position\"], [\"velocity\"], [\"Foo\"], [\"Bar\"]], "
22832283 "\"entities\":[\"e2\"], "
2284- "\"values\":[[{\"x\":20, \"y\":30}], [{\"x\":1, \"y\":1}], 0, 0, 0 ]"
2284+ "\"values\":[[{\"x\":20, \"y\":30}], [{\"x\":1, \"y\":1}], 0, 0]"
22852285 "}, {"
2286- "\"id_labels\":[[\"position\"], [\"mass\"], [\"Identifier\", \"Name\"] ], "
2286+ "\"id_labels\":[[\"position\"], [\"mass\"]], "
22872287 "\"entities\":[\"e3\"], "
2288- "\"values\":[[{\"x\":30, \"y\":40}], [{\"value\":100}], 0 ]}]"
2288+ "\"values\":[[{\"x\":30, \"y\":40}], [{\"value\":100}]]}]"
22892289 "}" );
22902290
22912291 ecs_os_free (json );
@@ -2366,6 +2366,106 @@ void SerializeIterToJson_serialize_table_w_var_labels(void) {
23662366 char * json = ecs_iter_to_json (world , & it , & desc );
23672367 test_assert (json != NULL );
23682368
2369+ test_str (json , "{\"vars\":[\"p\"], \"results\":["
2370+ "{"
2371+ "\"ids\":[[\"Position\"], [\"Foo\"]], "
2372+ "\"var_labels\":[\"parent\"], "
2373+ "\"parent\":\"Parent\", "
2374+ "\"entities\":[\"e1\"], "
2375+ "\"values\":[[{\"x\":10, \"y\":20}], 0]"
2376+ "}, {"
2377+ "\"ids\":[[\"Position\"], [\"Velocity\"], [\"Foo\"], [\"Bar\"]], "
2378+ "\"var_labels\":[\"parent\"], "
2379+ "\"parent\":\"Parent\", "
2380+ "\"entities\":[\"e2\"], "
2381+ "\"values\":[[{\"x\":20, \"y\":30}], [{\"x\":1, \"y\":1}], 0, 0]"
2382+ "}, {"
2383+ "\"ids\":[[\"Position\"], [\"Mass\"]], "
2384+ "\"var_labels\":[\"parent\"], "
2385+ "\"parent\":\"Parent\", "
2386+ "\"entities\":[\"e3\"], "
2387+ "\"values\":[[{\"x\":30, \"y\":40}], [{\"value\":100}]]}]"
2388+ "}" );
2389+
2390+ ecs_os_free (json );
2391+
2392+ ecs_rule_fini (f );
2393+
2394+ ecs_fini (world );
2395+ }
2396+
2397+ void SerializeIterToJson_serialize_table_w_private (void ) {
2398+ ecs_world_t * world = ecs_init ();
2399+
2400+ ECS_COMPONENT (world , Position );
2401+ ECS_COMPONENT (world , Velocity );
2402+ ECS_COMPONENT (world , Mass );
2403+ ECS_TAG (world , Foo );
2404+ ECS_TAG (world , Bar );
2405+
2406+ ecs_struct_init (world , & (ecs_struct_desc_t ){
2407+ .entity = ecs_id (Position ),
2408+ .members = {
2409+ {"x" , ecs_id (ecs_i32_t )},
2410+ {"y" , ecs_id (ecs_i32_t )}
2411+ }
2412+ });
2413+
2414+ ecs_struct_init (world , & (ecs_struct_desc_t ){
2415+ .entity = ecs_id (Velocity ),
2416+ .members = {
2417+ {"x" , ecs_id (ecs_i32_t )},
2418+ {"y" , ecs_id (ecs_i32_t )}
2419+ }
2420+ });
2421+
2422+ ecs_struct_init (world , & (ecs_struct_desc_t ){
2423+ .entity = ecs_id (Mass ),
2424+ .members = {
2425+ {"value" , ecs_id (ecs_i32_t )}
2426+ }
2427+ });
2428+
2429+ ecs_entity_t parent = ecs_new_entity (world , "Parent" );
2430+ ecs_doc_set_name (world , parent , "parent" );
2431+
2432+ ecs_entity_t e1 = ecs_new_entity (world , "e1" );
2433+ ecs_entity_t e2 = ecs_new_entity (world , "e2" );
2434+ ecs_entity_t e3 = ecs_new_entity (world , "e3" );
2435+
2436+ ecs_add_pair (world , e1 , EcsChildOf , parent );
2437+ ecs_add_pair (world , e2 , EcsChildOf , parent );
2438+ ecs_add_pair (world , e3 , EcsChildOf , parent );
2439+
2440+ ecs_set (world , e1 , Position , {10 , 20 });
2441+ ecs_set (world , e2 , Position , {20 , 30 });
2442+ ecs_set (world , e3 , Position , {30 , 40 });
2443+
2444+ ecs_add (world , e1 , Foo );
2445+ ecs_add (world , e2 , Foo );
2446+ ecs_add (world , e2 , Bar );
2447+
2448+ ecs_set (world , e2 , Velocity , {1 , 1 });
2449+ ecs_set (world , e3 , Mass , {100 });
2450+
2451+ ecs_rule_t * f = ecs_rule (world , {
2452+ .terms = {
2453+ { .id = ecs_id (Position ) },
2454+ { .first .id = EcsChildOf , .second .name = "p" , .second .flags = EcsIsVariable }
2455+ }
2456+ });
2457+
2458+ ecs_iter_t it = ecs_rule_iter (world , f );
2459+
2460+ ecs_iter_to_json_desc_t desc = {0 };
2461+ desc .serialize_table = true;
2462+ desc .serialize_entities = true;
2463+ desc .serialize_variable_labels = true;
2464+ desc .serialize_ids = true;
2465+ desc .serialize_private = true;
2466+ char * json = ecs_iter_to_json (world , & it , & desc );
2467+ test_assert (json != NULL );
2468+
23692469 test_str (json , "{\"vars\":[\"p\"], \"results\":["
23702470 "{"
23712471 "\"ids\":[[\"Position\"], [\"Foo\"], [\"flecs.core.Identifier\",\"flecs.core.Name\"], [\"flecs.core.ChildOf\",\"Parent\"]], "
0 commit comments