Last active
March 27, 2018 15:21
-
-
Save Vindaar/39358d5cd110ace7c08066604a616036 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro setTabFields[T: (float | int), N: int](tab: Table[string, seq[seq[T]]], | |
names: array[N, string], | |
chip: int, | |
obj: untyped): untyped = | |
## taking some table `tab` sets all fields of the table taken from an array `names` to the | |
## fields of the object `obj` of the same names as the names in the table | |
result = newStmtList() | |
let namesImpl = names.symbol.getImpl | |
for name in namesImpl: | |
let field = parseExpr(name.strVal) | |
result.add quote do: | |
`tab`[`name`][`chip`].add `obj`.`field` | |
macro `+`[N, M: int](a: array[N, string], b: array[M, string]): untyped = | |
let aImpl = a.symbol.getImpl | |
let bImpl = b.symbol.getImpl | |
var tree = nnkBracket.newTree() | |
for x in aImpl: | |
tree.add quote do: | |
`x` | |
for x in bImpl: | |
tree.add quote do: | |
`x` | |
result = nnkStmtList.newTree( | |
tree | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment