Skip to content

Commit

Permalink
get value
Browse files Browse the repository at this point in the history
Signed-off-by: George Lemon <[email protected]>
  • Loading branch information
georgelemon committed Apr 4, 2024
1 parent fe502c3 commit cad1be1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Binary file modified .github/voodoo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion src/voodoo/setget.nim
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ macro setters*(excludes: untyped, obj: untyped) =
## Optionally, you can exclude fields from generation
expectKind excludes, nnkBracket
excludeFields = excludes.mapIt($it)
echo obj[0].treeRepr
add obj[0][1], ident("setters")
obj

Expand All @@ -66,15 +67,17 @@ proc walkField(f: NimNode, id: NimNode) {.compileTime.} =
fieldName = $x
procName = genProcIdent(x)
else: discard
let paramIdent = ident(id.strVal[0].toLowerAscii & id.strVal[1..^1])
var body = newStmtList()
add body, newCommentStmtNode("Getter handle to return `" & $fieldName & "`")
add body, newDotExpr(paramIdent, ident(fieldName))
add genGetters[id.strVal],
newProc(
nnkPostfix.newTree(ident("*"), procName),
params = [
returnType,
nnkIdentDefs.newTree(
ident(id.strVal[0].toLowerAscii & id.strVal[1..^1]),
paramIdent,
id,
newEmptyNode()
),
Expand Down Expand Up @@ -105,6 +108,7 @@ macro getters*(obj: untyped) =
macro getters*(excludes: untyped, obj: untyped) =
expectKind excludes, nnkBracket
excludeFields = excludes.mapIt($it)
echo obj[0].treeRepr
add obj[0][1], ident("getters")
obj

Expand Down

0 comments on commit cad1be1

Please sign in to comment.