From 27d6efb5f5a076f825fe2da1875e0cabaf02b4e7 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 17 Nov 2021 23:03:07 +0800 Subject: + LuaMacro --- Tools/LuaMacro/tests/dll.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Tools/LuaMacro/tests/dll.c (limited to 'Tools/LuaMacro/tests/dll.c') diff --git a/Tools/LuaMacro/tests/dll.c b/Tools/LuaMacro/tests/dll.c new file mode 100644 index 0000000..629feae --- /dev/null +++ b/Tools/LuaMacro/tests/dll.c @@ -0,0 +1,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; +} + + -- cgit v1.1-26-g67d0