From 4b5e4cd1f21582f5e5fa682ab4e4bff252963468 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 29 Nov 2024 12:55:14 -0500 Subject: Change how types handle metamethods --- stdlib/structs.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 stdlib/structs.h (limited to 'stdlib/structs.h') diff --git a/stdlib/structs.h b/stdlib/structs.h new file mode 100644 index 00000000..b41dde77 --- /dev/null +++ b/stdlib/structs.h @@ -0,0 +1,24 @@ +// Metamethods for structs + +#include +#include + +#include "datatypes.h" +#include "types.h" +#include "util.h" + +PUREFUNC uint64_t Struct$hash(const void *obj, const TypeInfo_t *type); +PUREFUNC int32_t Struct$compare(const void *x, const void *y, const TypeInfo_t *type); +PUREFUNC bool Struct$equal(const void *x, const void *y, const TypeInfo_t *type); +PUREFUNC Text_t Struct$as_text(const void *obj, bool colorize, const TypeInfo_t *type); +PUREFUNC bool Struct$is_none(const void *obj, const TypeInfo_t *type); + +#define Struct$metamethods ((metamethods_t){ \ + .hash=Struct$hash, \ + .compare=Struct$compare, \ + .equal=Struct$equal, \ + .as_text=Struct$as_text, \ + .is_none=Struct$is_none, \ +}) + +// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 -- cgit v1.2.3