aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2019-01-27 17:07:20 -0600
committerGanesh Viswanathan <dev@genotrance.com>2019-01-27 17:07:20 -0600
commit3df901d2f0edb59c468d7827d6de004b6596eb10 (patch)
treed36cff381815baa4c2a83b090cb0d2ed41472f4b
parent6adf7f075acb3ecf6d56b198a0763e9006875891 (diff)
downloadnimterop-plugin.tar.gz
nimterop-plugin.zip
Minor fixesplugin
-rw-r--r--nimterop/cimport.nim17
-rw-r--r--nimterop/getters.nim16
-rw-r--r--nimterop/globals.nim4
-rw-r--r--nimterop/plugin.nim2
-rw-r--r--toast.nim10
5 files changed, 25 insertions, 24 deletions
diff --git a/nimterop/cimport.nim b/nimterop/cimport.nim
index 87a732c..7e9cd65 100644
--- a/nimterop/cimport.nim
+++ b/nimterop/cimport.nim
@@ -102,8 +102,8 @@ proc getToast(fullpath: string, recurse: bool = false): string =
if gStateCT.symOverride.len != 0:
cmd.add &" --symOverride={gStateCT.symOverride.join(\",\")}"
- if gStateCT.pluginFile.nBl:
- cmd.add &" --pluginFile={gStateCT.pluginFile.quoteShell}"
+ if gStateCT.pluginSourcePath.nBl:
+ cmd.add &" --pluginSourcePath={gStateCT.pluginSourcePath.quoteShell}"
cmd.add &" {fullpath.quoteShell}"
echo cmd
@@ -130,7 +130,7 @@ macro cOverride*(body): untyped =
##
## int svGetCallerInfo(const char** fileName, int *lineNumber);
##
- ## This might mapped to:
+ ## This might map to:
##
## .. code-block:: nim
##
@@ -197,6 +197,8 @@ macro cPlugin*(body): untyped =
## - `nskField` for struct field names
## - `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.
runnableExamples:
cPlugin:
import strutils
@@ -206,16 +208,15 @@ macro cPlugin*(body): untyped =
let
data = "import nimterop/plugin\n\n" & body.repr
- hash = data.hash()
- phash = if hash<0: -hash else: hash
- path = getTempDir() / "nimterop_" & $phash & ".nim"
+ hash = data.hash().abs()
+ path = getTempDir() / "nimterop_" & $hash & ".nim"
if not fileExists(path) or gStateCT.nocache or compileOption("forceBuild"):
writeFile(path, data)
doAssert fileExists(path), "Unable to write plugin file: " & path
- gStateCT.pluginFile = path
+ gStateCT.pluginSourcePath = path
proc cSearchPath*(path: string): string {.compileTime.}=
## Get full path to file or directory ``path`` in search path configured
@@ -231,7 +232,7 @@ proc cSearchPath*(path: string): string {.compileTime.}=
if result.len == 0:
var found = false
for inc in gStateCT.searchDirs:
- result = findPath(inc & "/" & path, fail = false)
+ result = findPath(inc / path, fail = false)
if result.len != 0:
found = true
break
diff --git a/nimterop/getters.nim b/nimterop/getters.nim
index 688ca23..6e3b31a 100644
--- a/nimterop/getters.nim
+++ b/nimterop/getters.nim
@@ -329,18 +329,18 @@ proc dll*(path: string): string =
result = dir / (DynlibFormat % name)
-proc loadPlugin*(fullpath: string) =
- doAssert fileExists(fullpath), "Plugin file does not exist: " & fullpath
+proc loadPlugin*(sourcePath: string) =
+ doAssert fileExists(sourcePath), "Plugin file does not exist: " & sourcePath
let
- pdll = fullpath.dll
+ pdll = sourcePath.dll
if not fileExists(pdll) or
- fullpath.getLastModificationTime() > pdll.getLastModificationTime():
- discard execAction("nim c --app:lib " & fullpath)
- doAssert fileExists(pdll), "No plugin binary generated for " & fullpath
+ sourcePath.getLastModificationTime() > pdll.getLastModificationTime():
+ discard execAction("nim c --app:lib " & sourcePath)
+ doAssert fileExists(pdll), "No plugin binary generated for " & sourcePath
let lib = loadLib(pdll)
- doAssert lib != nil, "Plugin $1 compiled to $2 failed to load" % [fullpath, pdll]
+ doAssert lib != nil, "Plugin $1 compiled to $2 failed to load" % [sourcePath, pdll]
- gStateRT.onSymbol = cast[onSymbolType](lib.symAddr("onSymbol"))
+ gStateRT.onSymbol = cast[OnSymbol](lib.symAddr("onSymbol"))
doAssert gStateRT.onSymbol != nil, "onSymbol() load failed from " & pdll
diff --git a/nimterop/globals.nim b/nimterop/globals.nim
index 57b9a81..86dc819 100644
--- a/nimterop/globals.nim
+++ b/nimterop/globals.nim
@@ -54,14 +54,14 @@ type
consts*, enums*, procs*, types*: HashSet[string]
constStr*, debugStr*, enumStr*, procStr*, typeStr*: string
- code*, currentHeader*, mode*, pluginFile*, sourceFile*: string
+ code*, currentHeader*, mode*, pluginSourcePath*, sourceFile*: string
ast*: Table[string, seq[ref Ast]]
data*: seq[tuple[name, val: string]]
when not declared(CIMPORT):
grammar*: seq[tuple[grammar: string, call: proc(ast: ref Ast, node: TSNode) {.nimcall.}]]
- onSymbol*: onSymbolType
+ onSymbol*: OnSymbol
var
gStateCT {.compiletime, used.}: State
diff --git a/nimterop/plugin.nim b/nimterop/plugin.nim
index 909643c..325abe5 100644
--- a/nimterop/plugin.nim
+++ b/nimterop/plugin.nim
@@ -5,4 +5,4 @@ type
name*: string
kind*: NimSymKind
- onSymbolType* = proc(sym: var Symbol) {.cdecl.} \ No newline at end of file
+ OnSymbol* = proc(sym: var Symbol) {.cdecl.} \ No newline at end of file
diff --git a/toast.nim b/toast.nim
index e555a62..a045d63 100644
--- a/toast.nim
+++ b/toast.nim
@@ -113,7 +113,7 @@ proc main(
defines: seq[string] = @[],
includeDirs: seq[string] = @[],
symOverride: seq[string] = @[],
- pluginFile: string = "",
+ pluginSourcePath: string = "",
source: seq[string],
) =
@@ -128,13 +128,13 @@ proc main(
defines: defines,
includeDirs: includeDirs,
symOverride: symOverride,
- pluginFile: pluginFile
+ pluginSourcePath: pluginSourcePath
)
gStateRT.symOverride = gStateRT.symOverride.getSplitComma()
- if pluginFile.nBl:
- loadPlugin(pluginFile)
+ if pluginSourcePath.nBl:
+ loadPlugin(pluginSourcePath)
if pgrammar:
parseGrammar()
@@ -151,7 +151,7 @@ when isMainModule:
"defines": "definitions to pass to preprocessor",
"includeDirs": "include directory to pass to preprocessor",
"symOverride": "skip generating specified symbols",
- "pluginFile": "Nim file to build and load as a plugin",
+ "pluginSourcePath": "Nim file to build and load as a plugin",
"preprocess": "run preprocessor on header",
"pgrammar": "print grammar",
"recurse": "process #include files",