From 5ee185a4896e43c67b6d299becfa616da78fb9f4 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 21 Mar 2025 21:48:53 -0400 Subject: Move stdlib into src/ --- src/stdlib/mutexeddata.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/stdlib/mutexeddata.c (limited to 'src/stdlib/mutexeddata.c') diff --git a/src/stdlib/mutexeddata.c b/src/stdlib/mutexeddata.c new file mode 100644 index 00000000..f47adfc1 --- /dev/null +++ b/src/stdlib/mutexeddata.c @@ -0,0 +1,38 @@ +// Mutexed data methods/type info +#include +#include +#include +#include +#include +#include +#include + +#include "bools.h" +#include "metamethods.h" +#include "optionals.h" +#include "text.h" +#include "util.h" + +static Text_t MutexedData$as_text(const void *m, bool colorize, const TypeInfo_t *type) +{ + auto mutexed = type->MutexedDataInfo; + Text_t typename = generic_as_text(NULL, false, mutexed.type); + if (!m) { + return Texts(colorize ? Text("\x1b[34;1mmutexed\x1b[m(") : Text("mutexed("), typename, Text(")")); + } + return Text$format(colorize ? "\x1b[34;1mmutexed %k<%p>\x1b[m" : "mutexed %k<%p>", &typename, *((MutexedData_t*)m)); +} + +static bool MutexedData$is_none(const void *m, const TypeInfo_t *) +{ + return *((MutexedData_t*)m) == NULL; +} + +public const metamethods_t MutexedData$metamethods = { + .as_text=MutexedData$as_text, + .is_none=MutexedData$is_none, + .serialize=cannot_serialize, + .deserialize=cannot_deserialize, +}; + +// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 -- cgit v1.2.3