Skip to content

Commit

Permalink
empty interface (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsumura-h authored Sep 4, 2021
1 parent 5aadc85 commit 739afb8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion interface_implements.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.2.1"
version = "0.2.2"
author = "dumblepy"
description = "Creating toInterface macro."
license = "MIT"
Expand Down
10 changes: 9 additions & 1 deletion src/interface_implements.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ macro implements*(implName, interfaceName, procs:untyped):untyped =
let procsStr = procs.repr
var tuples = ""
for i, aProc in procs:
if aProc.repr == "discard":
break
var args: seq[string]
var anonimousProcArgs: seq[string]
let procName = aProc[0]
Expand All @@ -21,7 +23,13 @@ macro implements*(implName, interfaceName, procs:untyped):untyped =
var tupleRow = fmt" {procName.repr}: proc({anonimousProcArgsStr}){returnType} = self.{procName.repr}({argPart})"
if i != 0: tuples.add(",\n")
tuples.add(tupleRow)
let resultStr = fmt"""proc toInterface*(self:{implName.repr}):{interfaceName.repr} =
let resultStr =
if tuples.len == 0:
fmt"""proc toInterface*(self:{implName.repr}):{interfaceName.repr} =
return ()
"""
else:
fmt"""proc toInterface*(self:{implName.repr}):{interfaceName.repr} =
return (
{tuples}
)
Expand Down

0 comments on commit 739afb8

Please sign in to comment.