/
lick.c
75 lines (68 loc) · 2.15 KB
/
lick.c
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
///\file lick.c
/// PNLick class - the interleaved data format
//
// (c) 2008 why the lucky stiff, the freelance professor
//
#include <stdio.h>
#include <stdlib.h>
#include "potion.h"
#include "internal.h"
PN potion_lick(Potion *P, PN name, PN inner, PN attr) {
vPN(Lick) lk = PN_ALLOC(PN_TLICK, struct PNLick);
lk->name = name;
lk->attr = attr;
lk->inner = inner;
return (PN)lk;
}
///\memberof PNLick
/// "attr" method
///\return the attached attr member PN
PN potion_lick_attr(Potion *P, PN cl, PN self) {
return ((struct PNLick *)self)->attr;
}
///\memberof PNLick
/// "licks" method. attached can be a string or PNTuple
///\return the attached licks PNTuple or PN_NIL
PN potion_lick_licks(Potion *P, PN cl, PN self) {
PN licks = ((struct PNLick *)self)->inner;
if (PN_IS_TUPLE(licks)) return licks;
return PN_NIL;
}
///\memberof PNLick
/// "name" method
///\return PNString
PN potion_lick_name(Potion *P, PN cl, PN self) {
return ((struct PNLick *)self)->name;
}
///\memberof PNLick
/// "text" method. attached can be a string or PNTuple
///\return the attached text PNString or PN_NIL
PN potion_lick_text(Potion *P, PN cl, PN self) {
PN text = ((struct PNLick *)self)->inner;
if (PN_IS_STR(text)) return text;
return PN_NIL;
}
///\memberof PNLick
/// "string" method
///\return space seperated PNString of the lick members: name inner attr
PN potion_lick_string(Potion *P, PN cl, PN self) {
PN out = potion_byte_str(P, "");
potion_bytes_obj_string(P, out, ((struct PNLick *)self)->name);
if (((struct PNLick *)self)->inner != PN_NIL) {
pn_printf(P, out, " ");
potion_bytes_obj_string(P, out, ((struct PNLick *)self)->inner);
}
if (((struct PNLick *)self)->attr != PN_NIL) {
pn_printf(P, out, " ");
potion_bytes_obj_string(P, out, ((struct PNLick *)self)->attr);
}
return PN_STR_B(out);
}
void potion_lick_init(Potion *P) {
PN lk_vt = PN_VTABLE(PN_TLICK);
potion_method(lk_vt, "attr", potion_lick_attr, 0);
potion_method(lk_vt, "licks", potion_lick_licks, 0);
potion_method(lk_vt, "name", potion_lick_name, 0);
potion_method(lk_vt, "string", potion_lick_string, 0);
potion_method(lk_vt, "text", potion_lick_text, 0);
}