Skip to content

Instantly share code, notes, and snippets.

@PhilipWitte
Last active August 29, 2015 14:20
Show Gist options
  • Save PhilipWitte/3bb61b3b9fdb0a7cd9c9 to your computer and use it in GitHub Desktop.
Save PhilipWitte/3bb61b3b9fdb0a7cd9c9 to your computer and use it in GitHub Desktop.
import macros
{.emit:"""
void foobar(int i, ...) {
va_list args;
int j;
printf("Count: %i\n", i);
va_start(args, i);
for (j = 0; j < i; j++) {
int x = va_arg(args, int);
printf("%i\n", x);
}
va_end(args);
}
""".}
proc foobar(i:cint) {.importc varargs.}
macro barfoo(nums:varargs[cint]): stmt =
result = quote do:
foobar(`nums`.len.cint)
for n in nums.children:
result[0].add(n)
barfoo(1, 2, 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment