diff --git a/README.md b/README.md index f9cb9f6..f14070b 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ cImport("clib.h") cCompile("clib/src/*.c") ``` -Check out [template.nim](https://github.com/nimterop/nimterop/blob/master/nimterop/template.nim) as a starting point for wrapping a new library. The template can be copied and trimmed down and modified as required. +Check out [template.nim](https://github.com/nimterop/nimterop/blob/master/nimterop/template.nim) as a starting point for wrapping a new library. The template can be copied and trimmed down and modified as required. [templite.nim](https://github.com/nimterop/nimterop/blob/master/nimterop/templite.nim) is a shorter version for more experienced users. Refer to the ```tests``` directory for examples on how the library can be used. diff --git a/nimterop/cimport.nim b/nimterop/cimport.nim index d2c1e69..764fc10 100644 --- a/nimterop/cimport.nim +++ b/nimterop/cimport.nim @@ -3,7 +3,8 @@ This is the main nimterop import file to help with wrapping C/C++ source code. Check out `template.nim `_ as a starting point for wrapping a new library. The template can be copied and -trimmed down and modified as required. +trimmed down and modified as required. `templite.nim `_ is a shorter +version for more experienced users. All ``{.compileTime.}`` procs must be used in a compile time context, e.g. using: @@ -188,6 +189,9 @@ macro cOverride*(body): untyped = ## Using the `cOverride() `_ block, nimterop ## can be instructed to skip over ``svGetCallerInfo()``. This works for procs, ## consts and types. + ## + ## `cOverride() `_ only affects calls to + ## `cImport() `_ that follow it. proc recFindIdent(node: NimNode): seq[string] = if node.kind != nnkIdent: @@ -209,6 +213,9 @@ macro cOverride*(body): untyped = proc cSkipSymbol*(skips: seq[string]) {.compileTime.} = ## Similar to `cOverride() `_, this macro allows ## filtering out symbols not of interest from the generated output. + ## + ## `cSkipSymbol() `_ only affects calls to + ## `cImport() `_ that follow it. runnableExamples: static: cSkipSymbol @["proc1", "Type2"] gStateCT.symOverride.add skips @@ -239,7 +246,10 @@ macro cPlugin*(body): untyped = ## - `nskEnumField` for enum (field) names, though they are in the global namespace as `nskConst` ## - `nskProc` - for proc names ## - ## `nimterop/plugins` is implicitly imported to provide access to standard plugin facilities. + ## ``nimterop/plugins`` is implicitly imported to provide access to standard plugin facilities. + ## + ## `cPlugin() `_ only affects calls to + ## `cImport() `_ that follow it. runnableExamples: cPlugin: import strutils diff --git a/nimterop/template.nim b/nimterop/template.nim index aea8535..04a0219 100644 --- a/nimterop/template.nim +++ b/nimterop/template.nim @@ -52,7 +52,7 @@ cOverride: symbol = object # Specify include directories for gcc and Nim -cInclude(srcDir/"include") +cIncludeDir(srcDir/"include") # Define global symbols cDefine("SYMBOL", "value") @@ -64,7 +64,7 @@ cDefine("SYMBOL", "value") {.passL: "flags".} # Compile in any common source code -cCompile(srcDir/"windows/file.c") +cCompile(srcDir/"file.c") # Perform OS specific tasks when defined(windows): diff --git a/nimterop/templite.nim b/nimterop/templite.nim new file mode 100644 index 0000000..71262df --- /dev/null +++ b/nimterop/templite.nim @@ -0,0 +1,36 @@ +import os, strutils + +import nimterop/[cimport, git, paths] + +const + baseDir = currentSourcePath.parentDir()/"build" + + srcDir = baseDir/"project" + +static: + cDebug() + cDisableCaching() + + gitPull("https://github.com/user/project", outdir = srcDir, plist = """ +include/*.h +src/*.c +""", checkout = "tag/branch/hash") + + downloadUrl("https://hostname.com/file.h", outdir = srcDir) + +cIncludeDir(srcDir/"include") + +cDefine("SYMBOL", "value") + +{.passC: "flags".} +{.passL: "flags".} + +cCompile(srcDir/"file.c") + +cPlugin: + import strutils + + proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} = + sym.name = sym.name.strip(chars = {'_'}) + +cImport(srcDir/"include/file.h", recurse = true)