Skip to content

Instantly share code, notes, and snippets.

@PhilipWitte
Last active August 29, 2015 14:20
Show Gist options
  • Save PhilipWitte/3f77d0876ca82d13c6bb to your computer and use it in GitHub Desktop.
Save PhilipWitte/3f77d0876ca82d13c6bb to your computer and use it in GitHub Desktop.
type
PBCEnv = ref object
PBCPattern = int
proc pbc_pattern_new(e:PBCEnv, msg, format: cstring, offsets: varargs[int]): int =
echo msg, ", ", format
for n in offsets:
result += n
macro wrapped_pbc_pattern_new(e: PBCEnv, msg, format: cstring, offsets: varargs[int]): expr =
result = newCall(!"pbc_pattern_new", e, msg, format)
for n in offsets.children:
result.add(n)
echo result.treeRepr
template newPattern*(e: PBCEnv, msg, format: string, offsets: varargs[int]): PBCPattern =
let result = wrapped_pbc_pattern_new(e, msg, format, offsets)
if result == 0: # changed this to 'int' for my test
raise newException(AssertionError, "pbc_pattern_new returned NULL")
result
echo newPattern(PBCEnv(), "msg", "fmt", 1, 2, 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment