From 4f1da7957ba6e0e21c3b2487bf88d2fde5593729 Mon Sep 17 00:00:00 2001 From: Will Szumski Date: Sun, 4 Jan 2015 19:22:05 +0000 Subject: [PATCH] initial support for user defined helpers from within QtType. Implemented by delaying the definition of user deined items (procs, methods, etc.) until after create. This was necessary as create is currently defined as a template and we can't use a forward declaration. --- Nim/NimQml/NimQmlMacros.nim | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Nim/NimQml/NimQmlMacros.nim b/Nim/NimQml/NimQmlMacros.nim index b1fd6a3..8dca486 100644 --- a/Nim/NimQml/NimQmlMacros.nim +++ b/Nim/NimQml/NimQmlMacros.nim @@ -13,7 +13,6 @@ template debug(body: stmt): stmt = else: {.pop.} - let nimFromQtVariant {.compileTime.} = { "int" : "intVal", "string" : "stringVal", @@ -235,6 +234,8 @@ macro QtType*(qtDecl: stmt): stmt {.immediate.} = var slots = newSeq[PNimrodNode]() var properties = newSeq[PNimrodNode]() var signals = newSeq[PNimrodNode]() + # holds all user defined procedures so we can add them after create + var userDefined = newSeq[PNimrodNode]() # assume only one type per section for now var typ: PNimrodNode for it in qtDecl.children(): @@ -267,6 +268,10 @@ macro QtType*(qtDecl: stmt): stmt {.immediate.} = it.body = addSignalBody(it) result.add it signals.add it + else: + userDefined.add it + elif it.kind == nnkProcDef: + userDefined.add it else: # everything else should pass through unchanged result.add it @@ -368,5 +373,9 @@ macro QtType*(qtDecl: stmt): stmt {.immediate.} = #echo repr createProto result.add createProto + + for fn in userDefined: + result.add fn + debug: echo repr result