Skip to content

Commit cad1be1

Browse files
committed
get value
Signed-off-by: George Lemon <georgelemon@protonmail.com>
1 parent fe502c3 commit cad1be1

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

.github/voodoo.png

6.61 KB
Loading

src/voodoo/setget.nim

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ macro setters*(excludes: untyped, obj: untyped) =
4040
## Optionally, you can exclude fields from generation
4141
expectKind excludes, nnkBracket
4242
excludeFields = excludes.mapIt($it)
43+
echo obj[0].treeRepr
4344
add obj[0][1], ident("setters")
4445
obj
4546

@@ -66,15 +67,17 @@ proc walkField(f: NimNode, id: NimNode) {.compileTime.} =
6667
fieldName = $x
6768
procName = genProcIdent(x)
6869
else: discard
70+
let paramIdent = ident(id.strVal[0].toLowerAscii & id.strVal[1..^1])
6971
var body = newStmtList()
7072
add body, newCommentStmtNode("Getter handle to return `" & $fieldName & "`")
73+
add body, newDotExpr(paramIdent, ident(fieldName))
7174
add genGetters[id.strVal],
7275
newProc(
7376
nnkPostfix.newTree(ident("*"), procName),
7477
params = [
7578
returnType,
7679
nnkIdentDefs.newTree(
77-
ident(id.strVal[0].toLowerAscii & id.strVal[1..^1]),
80+
paramIdent,
7881
id,
7982
newEmptyNode()
8083
),
@@ -105,6 +108,7 @@ macro getters*(obj: untyped) =
105108
macro getters*(excludes: untyped, obj: untyped) =
106109
expectKind excludes, nnkBracket
107110
excludeFields = excludes.mapIt($it)
111+
echo obj[0].treeRepr
108112
add obj[0][1], ident("getters")
109113
obj
110114

0 commit comments

Comments
 (0)