Skip to content

Commit e6bc797

Browse files
authored
Merge pull request #50 from SciNim/devel
Devel
2 parents da5f633 + 32a2f82 commit e6bc797

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

nimjl.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Nimjl
22
# Licensed and distributed under MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
3-
version = "0.8.0"
3+
version = "0.8.2"
44
author = "Regis Caillaud"
55
description = "Nim Julia bridge"
66
license = "MIT"

readme.md

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Mostly quality-of-life improvements, especially when handling arrays.
4949

5050
## Limitations
5151

52+
* Avoid using global scope for Julia function call. Always have everything inse proc / func. It's good practice anyway
53+
5254
* Value conversion Nim -> Julia are done **by copy**.
5355
* Arrays are an exception to this rule and can be created from buffer / are accessible using a buffer.
5456

@@ -63,24 +65,33 @@ Mostly quality-of-life improvements, especially when handling arrays.
6365
* If you need Windows support, consider opening an issue or a PR :).
6466
* Otherwise, just use WSL
6567

66-
# Examples
68+
# Examples & tips
69+
70+
## Examples
6771

6872
Here is the basic example:
6973
```nim
7074
import nimjl
75+
proc main() =
76+
Julia.init() # Initialize Julia VM. Subsequent call will be ignored
77+
78+
var myval = 4.0'f64
79+
# Call Julia function "sqrt" and convert the result to a float
80+
var res = Julia.sqrt(myval).to(float64)
81+
echo res # 2.0
7182
72-
Julia.init() # Initialize Julia VM. Subsequent call will be ignored
73-
74-
var myval = 4.0'f64
75-
# Call Julia function "sqrt" and convert the result to a float
76-
var res = Julia.sqrt(myval).to(float64)
77-
echo res # 2.0
83+
when isMainModule:
84+
main()
7885
7986
```
8087

88+
JlVmExit() seems optionnal. It's present in the C API but not calling it doesn't seem to cause any problem.
89+
90+
Nonetheless, if you use OS resources from Julia it is probably better to call Julia.exit() / JlVmExit() for a clean exit.
91+
8192
## Setting up Julia dependency
8293

83-
It is now possible to embed Julia files inside a Nim compiled binary to easily distribute Julia code. To make distribution possible, an API to call ``Pkg.add("...")`` has also been added **with version number easy to specify**.
94+
* It is now possible to embed Julia files inside a Nim compiled binary to easily distribute Julia code. To make distribution possible, an API to call ``Pkg.add("...")`` has also been added **with version number easy to specify**.
8495

8596
```nim
8697
import nimjl
@@ -100,10 +111,25 @@ Julia.init:
100111
# embed specific file; path should be relative to ``getProjectPath()``
101112
file("localfile.jl")
102113
```
103-
See examples/ex09_embed_file.nim for a concrete example
114+
115+
Note that the order of the file matters.
116+
See examples/ex09_embed_file.nim for a concrete example.
104117

105118
Take a look at ``tests/`` or ``examples/`` folder for typical examples.
106119

120+
* You can use Pkg: activate() to setup a virtual env
121+
* Alternatively, you can embed a Julia file that setup your environment and dependencies and embed it **first**.
122+
* Because files are evaluated in the order they are embedded, it will deterine the env for all the other files.
123+
124+
## Debugging
125+
126+
* Most error will come from incorrect type passed between Julia and Nim. Check function interface and return type first.
127+
128+
* If you have random segfault that are non-reproductible, that may be a cause of the Julia GC cleaning memory that Nim uses. Consider using jlGcRoot.
129+
130+
* If you do not work with fixed version package for Julia, you are at risk of code breaking when packages are updated / upgraded.
131+
132+
107133
# License
108134

109135
This project is released under MIT License.

0 commit comments

Comments
 (0)