Properly link flecs library
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
#ifndef BASICS_ENUM_H
|
||||
#define BASICS_ENUM_H
|
||||
|
||||
/* This generated file contains includes for project dependencies */
|
||||
#include "basics_enum/bake_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
)
|
||||
(.)
|
||||
.|.
|
||||
| |
|
||||
_.--| |--._
|
||||
.-'; ;`-'& ; `&.
|
||||
\ & ; & &_/
|
||||
|"""---...---"""|
|
||||
\ | | | | | | | /
|
||||
`---.|.|.|.---'
|
||||
|
||||
* This file is generated by bake.lang.c for your convenience. Headers of
|
||||
* dependencies will automatically show up in this file. Include bake_config.h
|
||||
* in your main project file. Do not edit! */
|
||||
|
||||
#ifndef BASICS_ENUM_BAKE_CONFIG_H
|
||||
#define BASICS_ENUM_BAKE_CONFIG_H
|
||||
|
||||
/* Headers of public dependencies */
|
||||
#include <flecs.h>
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"id": "basics_enum",
|
||||
"type": "application",
|
||||
"value": {
|
||||
"use": [
|
||||
"flecs"
|
||||
],
|
||||
"public": false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
#include <basics_enum.h>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef enum {
|
||||
Red,
|
||||
Green,
|
||||
Blue
|
||||
} Color;
|
||||
|
||||
typedef struct {
|
||||
Color color;
|
||||
} TypeWithEnum;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
ecs_world_t *ecs = ecs_init_w_args(argc, argv);
|
||||
|
||||
// Register component as usual
|
||||
ECS_COMPONENT(ecs, Color);
|
||||
ECS_COMPONENT(ecs, TypeWithEnum);
|
||||
|
||||
// Add reflection data to components
|
||||
ecs_enum(ecs, {
|
||||
.entity = ecs_id(Color), // Make sure to use existing id
|
||||
.constants = {
|
||||
{ .name = "Red", .value = Red },
|
||||
{ .name = "Green", .value = Green },
|
||||
{ .name = "Blue", .value = Blue }
|
||||
}
|
||||
});
|
||||
|
||||
ecs_struct(ecs, {
|
||||
.entity = ecs_id(TypeWithEnum), // Make sure to use existing id
|
||||
.members = {
|
||||
{ .name = "color", .type = ecs_id(Color) }
|
||||
}
|
||||
});
|
||||
|
||||
// Create entity with Position as usual
|
||||
ecs_entity_t ent = ecs_new_id(ecs);
|
||||
ecs_set(ecs, ent, TypeWithEnum, {Green});
|
||||
|
||||
// Convert position component to flecs expression string
|
||||
const TypeWithEnum *ptr = ecs_get(ecs, ent, TypeWithEnum);
|
||||
char *str = ecs_ptr_to_expr(ecs, ecs_id(TypeWithEnum), ptr);
|
||||
printf("%s\n", str); // {color: Green}
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(ecs);
|
||||
}
|
||||
Reference in New Issue
Block a user