aboutsummaryrefslogtreecommitdiff
path: root/stdlib/bools.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-11-29 12:55:14 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-11-29 12:55:14 -0500
commit4b5e4cd1f21582f5e5fa682ab4e4bff252963468 (patch)
treee8fecb01f444c1d392c09255adba5cf6b312b326 /stdlib/bools.c
parent0b0e0a0a1d41e9574de8dc17c688a4894c5e7f92 (diff)
Change how types handle metamethods
Diffstat (limited to 'stdlib/bools.c')
-rw-r--r--stdlib/bools.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/stdlib/bools.c b/stdlib/bools.c
index 50cd3f4c..5e0ade37 100644
--- a/stdlib/bools.c
+++ b/stdlib/bools.c
@@ -12,14 +12,13 @@
#include "text.h"
#include "util.h"
-PUREFUNC public Text_t Bool$as_text(const bool *b, bool colorize, const TypeInfo_t *type)
+PUREFUNC public Text_t Bool$as_text(const void *b, bool colorize, const TypeInfo_t*)
{
- (void)type;
if (!b) return Text("Bool");
if (colorize)
- return *b ? Text("\x1b[35myes\x1b[m") : Text("\x1b[35mno\x1b[m");
+ return *(Bool_t*)b ? Text("\x1b[35myes\x1b[m") : Text("\x1b[35mno\x1b[m");
else
- return *b ? Text("yes") : Text("no");
+ return *(Bool_t*)b ? Text("yes") : Text("no");
}
PUREFUNC public OptionalBool_t Bool$parse(Text_t text)
@@ -39,11 +38,20 @@ PUREFUNC public OptionalBool_t Bool$parse(Text_t text)
}
}
+static bool Bool$is_none(const void *b, const TypeInfo_t*)
+{
+ return *(OptionalBool_t*)b == NONE_BOOL;
+}
+
+static const metamethods_t Bool$metamethods = {
+ .as_text=Bool$as_text,
+ .is_none=Bool$is_none,
+};
+
public const TypeInfo_t Bool$info = {
.size=sizeof(bool),
.align=__alignof__(bool),
- .tag=CustomInfo,
- .CustomInfo={.as_text=(void*)Bool$as_text},
+ .metamethods=Bool$metamethods,
};
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0