Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function-like macros #35

Open
lithiumtoast opened this issue Aug 26, 2021 · 3 comments
Open

Function-like macros #35

lithiumtoast opened this issue Aug 26, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@lithiumtoast
Copy link
Member

No description provided.

@lithiumtoast lithiumtoast added the help wanted Extra attention is needed label Aug 26, 2021
@lithiumtoast
Copy link
Member Author

Object-like macros have been implemented. It would just be taking it to the next level with function-like macros.

@lithiumtoast
Copy link
Member Author

C header .h files may contain source code. Since function macros could technically be seen as "source code" and subject to terms and agreements or otherwise licensing, transpiling C function macros into C# code would have to be optional. For libraries that are free and open source, I would recommend transpiling function-like macros; otherwise, I would advise caution and suggest you don't use the option unless you know 100% what you are doing.

@lithiumtoast lithiumtoast added the enhancement New feature or request label Apr 24, 2022
@lithiumtoast
Copy link
Member Author

lithiumtoast commented Jun 1, 2022

Now that object-like macros are working well enough, this should be explored more. I need it for flecs-cs.

E.g. the function-like macro ECS_COMPONENT_DEFINE which takes an ecs_world, and id as "parameters". Inferring the type should be possible for world but the type for id would need to be a generic type in C#. It's not clear right now how to reliably tell when a function-like macro "parameter" is a type.

#define ECS_COMPONENT_DEFINE(world, id) \
    {\
        ecs_component_desc_t desc = {0}; \
        desc.entity.entity = ecs_id(id); \
        desc.entity.name = #id; \
        desc.entity.symbol = #id; \
        desc.size = sizeof(id); \
        desc.alignment = ECS_ALIGNOF(id); \
        ecs_id(id) = ecs_component_init(world, &desc);\
        ecs_assert(ecs_id(id) != 0, ECS_INVALID_PARAMETER, NULL);\
    }

@lithiumtoast lithiumtoast removed the help wanted Extra attention is needed label Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant