diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2020-04-12 23:12:38 -0500 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2020-04-12 23:12:38 -0500 |
| commit | b2de34328a92c6c9a63e3db12d4f78e7e5831d8c (patch) | |
| tree | 58249cc5a4b3c209dd4f7e4d0f1bf0f6b2be5495 | |
| parent | 0afb634b59d55ff369bd25d85e13d156c6836db0 (diff) | |
| download | nimterop-cpluginpath.tar.gz nimterop-cpluginpath.zip | |
No explicit imports for cPluginPathcpluginpath
| -rw-r--r-- | nimterop/cimport.nim | 16 | ||||
| -rw-r--r-- | tests/tnimterop_c_plugin.nim | 2 |
2 files changed, 12 insertions, 6 deletions
diff --git a/nimterop/cimport.nim b/nimterop/cimport.nim index 69aaf90..382c034 100644 --- a/nimterop/cimport.nim +++ b/nimterop/cimport.nim @@ -268,12 +268,12 @@ proc cSkipSymbol*(skips: seq[string]) {.compileTime.} = static: cSkipSymbol @["proc1", "Type2"] gStateCT.symOverride.add skips -proc cPluginHelper(body: string) = +proc cPluginHelper(body: string, imports = "import macros, nimterop/plugin\n\n") = gStateCT.pluginSource = body if gStateCT.pluginSource.nBl or gStateCT.overrides.nBl: let - data = "import macros, nimterop/plugin\n\n" & body & "\n\n" & gStateCT.overrides + data = imports & body & "\n\n" & gStateCT.overrides hash = data.hash().abs() path = getProjectCacheDir("cPlugins", forceClean = false) / "nimterop_" & $hash & ".nim" @@ -347,14 +347,18 @@ macro cPluginPath*(path: static[string]): untyped = ## preferable to have it stored in a separate source file. This allows for reuse ## across multiple wrappers when applicable. ## - ## The `cPluginPath()` macro enables this functionality - provide a path to the + ## The `cPluginPath()` macro enables this functionality - specify the path to the ## plugin file and it will be consumed in the same way as `cPlugin()`. ## ## `path` is relative to the current dir and not necessarily relative to the - ## location of the wrapper file. Use `currentSourcePath.parentDir()` to specify - ## path relative to the wrapper file. + ## location of the wrapper file. Use `currentSourcePath` to specify a path relative + ## to the wrapper file. + ## + ## Unlike `cPlugin()`, this macro also does not implicitly import any other modules + ## since the standalone plugin file will need explicit imports for `nim check` and + ## suggestions to work. `import nimterop/plugin` is required for all plugins. doAssert fileExists(path), "Plugin file not found: " & path - cPluginHelper(readFile(path)) + cPluginHelper(readFile(path), imports = "") proc cSearchPath*(path: string): string {.compileTime.}= ## Get full path to file or directory `path` in search path configured diff --git a/tests/tnimterop_c_plugin.nim b/tests/tnimterop_c_plugin.nim index 68bb4d6..90ac2ab 100644 --- a/tests/tnimterop_c_plugin.nim +++ b/tests/tnimterop_c_plugin.nim @@ -1,3 +1,5 @@ +import nimterop/plugin + import strutils proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} = |
