From 31527a82402efe58c3eef7e60b196861defe486c Mon Sep 17 00:00:00 2001 From: Ganesh Viswanathan Date: Fri, 1 Nov 2019 17:45:33 -0500 Subject: Update docs, minor optimization --- nimterop/cimport.nim | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/nimterop/cimport.nim b/nimterop/cimport.nim index aabeadc..65a5401 100644 --- a/nimterop/cimport.nim +++ b/nimterop/cimport.nim @@ -198,8 +198,10 @@ macro cOverride*(body): untyped = ## can be instructed to use this definition of `svGetCallerInfo()` instead. ## This works for procs, consts and types. ## - ## `cOverride() `_ only affects calls to - ## `cImport() `_ that follow it. + ## `cOverride()` only affects the next `cImport()` call. This is because any + ## recognized symbols get overridden in place and any remaining symbols get + ## added to the top. If reused, the next `cImport()` would add those symbols + ## again leading to redefinition errors. iterator findOverrides(node: NimNode): tuple[name, override: string, kind: NimNodeKind] = for child in node: @@ -571,6 +573,10 @@ macro cImport*(filename: static string, recurse: static bool = false, dynlib: st ## be ignored for the foreseeable future. ## ## `flags` can be used to pass any other command line arguments to `toast`. + ## + ## `cImport()` consumes and resets preceding `cOverride()` calls. `cPlugin()` + ## is retained for the next `cImport()` call unless a new `cPlugin()` call is + ## defined. result = newNimNode(nnkStmtList) @@ -587,8 +593,9 @@ macro cImport*(filename: static string, recurse: static bool = false, dynlib: st output = getToast(fullpath, recurse, dynlib, mode, flags) # Reset plugin and overrides for next cImport - gStateCT.pluginSourcePath = "" - gStateCT.overrides = "" + if gStateCT.overrides.nBl: + gStateCT.pluginSourcePath = "" + gStateCT.overrides = "" if gStateCT.debug: echo output -- cgit v1.2.3