summaryrefslogtreecommitdiff
path: root/Tools/LuaMacro/tests/dll.c
blob: 629feae5a5fd6d47040c63b8150c3c3fdedf2301 (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
// luam -C -lcexport dll.c
// expands this file into pukka C and creates/updates dll.h

#include "dll.h"

export {
typedef struct {
   int ival;
} MyStruct;
}

// yes we could use #define here, but it's sometimes useful to have another level
// of macro substitution
def_ alloc(T) (T*)malloc(sizeof(T))

// Plus, LuaMacro can do operator replacements. This is Ruby-style 'field' access
def_ @ self->

export MyStruct *create() {
    return alloc(MyStruct);
}

def_ This MyStruct *self

export int one(This) {
    return @ival + 1
}

export int two(This) {
    return 2*@ival;
}

export void set(This,int i) {
    @ival = i;
}