aboutsummaryrefslogtreecommitdiff
path: root/stdlib/structs.h
blob: d198245610865bc4a108c9b5e76ddc1c78838d22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Metamethods for structs

#include <stdbool.h>
#include <stdint.h>

#include "datatypes.h"
#include "types.h"
#include "util.h"

PUREFUNC uint64_t Struct$hash(const void *obj, const TypeInfo_t *type);
PUREFUNC uint64_t PackedData$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 bool PackedData$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);
void Struct$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type);
void Struct$deserialize(FILE *in, void *outval, List_t *pointers, 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, \
    .serialize=Struct$serialize, \
    .deserialize=Struct$deserialize, \
})

#define PackedData$metamethods ((metamethods_t){ \
    .hash=PackedData$hash, \
    .compare=Struct$compare, \
    .equal=PackedData$equal, \
    .as_text=Struct$as_text, \
    .is_none=Struct$is_none, \
    .serialize=Struct$serialize, \
    .deserialize=Struct$deserialize, \
})

// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0