Add lite template, clarify order of calls
This commit is contained in:
parent
2352e77c5e
commit
78d116b205
4 changed files with 51 additions and 5 deletions
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ This is the main nimterop import file to help with wrapping C/C++ source code.
|
|||
|
||||
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.
|
||||
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.
|
||||
|
||||
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() <cimport.html#cOverride.m,>`_ block, nimterop
|
||||
## can be instructed to skip over ``svGetCallerInfo()``. This works for procs,
|
||||
## consts and types.
|
||||
##
|
||||
## `cOverride() <cimport.html#cOverride.m,>`_ only affects calls to
|
||||
## `cImport() <cimport.html#cImport.m,>`_ 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() <cimport.html#cOverride.m,>`_, this macro allows
|
||||
## filtering out symbols not of interest from the generated output.
|
||||
##
|
||||
## `cSkipSymbol() <cimport.html#cSkipSymbol.m%2Cseq[string]>`_ only affects calls to
|
||||
## `cImport() <cimport.html#cImport.m,>`_ 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() <cimport.html#cPlugin.m,>`_ only affects calls to
|
||||
## `cImport() <cimport.html#cImport.m,>`_ that follow it.
|
||||
runnableExamples:
|
||||
cPlugin:
|
||||
import strutils
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
36
nimterop/templite.nim
Normal file
36
nimterop/templite.nim
Normal file
|
|
@ -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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue