diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-03-21 21:48:53 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-03-21 21:48:53 -0400 |
| commit | 5ee185a4896e43c67b6d299becfa616da78fb9f4 (patch) | |
| tree | 183ceef2fd21230c89334d7d039255d1c86c5dca /src/stdlib/enums.h | |
| parent | f4aaf7b73481248f6768302be688700a364a1af8 (diff) | |
Move stdlib into src/
Diffstat (limited to 'src/stdlib/enums.h')
| -rw-r--r-- | src/stdlib/enums.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/stdlib/enums.h b/src/stdlib/enums.h new file mode 100644 index 00000000..b5427711 --- /dev/null +++ b/src/stdlib/enums.h @@ -0,0 +1,38 @@ +// Metamethods for enums + +#include <stdbool.h> +#include <stdint.h> + +#include "datatypes.h" +#include "types.h" +#include "util.h" + +PUREFUNC uint64_t Enum$hash(const void *obj, const TypeInfo_t *type); +PUREFUNC int32_t Enum$compare(const void *x, const void *y, const TypeInfo_t *type); +PUREFUNC bool Enum$equal(const void *x, const void *y, const TypeInfo_t *type); +PUREFUNC Text_t Enum$as_text(const void *obj, bool colorize, const TypeInfo_t *type); +PUREFUNC bool Enum$is_none(const void *obj, const TypeInfo_t *type); +void Enum$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type); +void Enum$deserialize(FILE *in, void *outval, Array_t *pointers, const TypeInfo_t *type); + +#define Enum$metamethods { \ + .as_text=Enum$as_text, \ + .compare=Enum$compare, \ + .equal=Enum$equal, \ + .hash=Enum$hash, \ + .is_none=Enum$is_none, \ + .serialize=Enum$serialize, \ + .deserialize=Enum$deserialize, \ +} + +#define PackedDataEnum$metamethods { \ + .hash=PackedData$hash, \ + .compare=Enum$compare, \ + .equal=PackedData$equal, \ + .as_text=Enum$as_text, \ + .is_none=Enum$is_none, \ + .serialize=Enum$serialize, \ + .deserialize=Enum$deserialize, \ +} + +// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 |
