From 788a5a1f6faaf4b7070565b91c86f84f78b98341 Mon Sep 17 00:00:00 2001 From: Pihkaal Date: Tue, 24 Mar 2026 23:05:14 +0100 Subject: [PATCH] chore: update readme --- README.md | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/README.md b/README.md index 84d0948..9b2dd6e 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,71 @@ > Work in progress. This is not finished at all, I'm just experimenting. Meta Programming Header Only Library for C + +## Current limitations + +- Only parses `typedef struct { ... } type_name;` +- Will generate colliding definitions in case of types with the same name +- Requires `stb_c_lexer` + +## Quick start + +Current implementation depends on `stb_c_lexer`, in future I'll use my own lexer. Because of the current setup, cmeta is not easy to use, remember, it's not finished! + +1. Create `main.c` + +```c +typedef struct { + int int_field; + const char *char_ptr_field; +} My_Struct; + +int main(void) { + return 0; +} +``` + +2. Create `cmeta.c` + +You only have to call `process_file` with a file to generate type infos etc in `cmeta.h`. + +```c +#define CMETA_COMPTIME +#include "cmeta.h" + +int main(void) { + if (!process_file("./main.c")) return 1; + + return 0; +} +``` + +3. Build and cmeta + +As mentionned before, `stb_c_lexer` is currently required, it will be removed in the future. + +```console +$ gcc cmeta.c -I./third_party/ -o cmeta +$ ./cmeta +``` + +4. Enjoy! + +You can now inspect your types! + +```c +#include "cmeta.h" + +typedef struct { + int int_field; + const char* char_field; +} My_Struct; + +int main(void) { + printf("My_Struct.name = %s\n", my_struct_info.name); + printf("My_Struct.fields_count = %zu\n", my_struct_info.fields_count); + return 0; +} +``` + +It runs `gcc -E`, so it process everything your code uses, including structs from cmeta itself.