From bf8569d93093e0eb334c06aa1bf003124a570fa1 Mon Sep 17 00:00:00 2001 From: Regis Caillaud <35006197+Clonkk@users.noreply.github.com> Date: Tue, 26 Mar 2024 23:19:55 +0100 Subject: [PATCH 1/3] Update readme.md --- readme.md | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 494b927..71b20b9 100644 --- a/readme.md +++ b/readme.md @@ -49,6 +49,8 @@ Mostly quality-of-life improvements, especially when handling arrays. ## Limitations +* Avoid using global scope for Julia function call. Always have everything inse proc / func. It's good practice anyway + * Value conversion Nim -> Julia are done **by copy**. * Arrays are an exception to this rule and can be created from buffer / are accessible using a buffer. @@ -63,7 +65,9 @@ Mostly quality-of-life improvements, especially when handling arrays. * If you need Windows support, consider opening an issue or a PR :). * Otherwise, just use WSL -# Examples +# Examples & tips + +## Examples Here is the basic example: ```nim @@ -80,7 +84,7 @@ echo res # 2.0 ## Setting up Julia dependency -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**. +* 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**. ```nim import nimjl @@ -100,10 +104,25 @@ Julia.init: # embed specific file; path should be relative to ``getProjectPath()`` file("localfile.jl") ``` -See examples/ex09_embed_file.nim for a concrete example + +Note that the order of the file matters. +See examples/ex09_embed_file.nim for a concrete example. Take a look at ``tests/`` or ``examples/`` folder for typical examples. +* You can use Pkg: activate() to setup a virtual env + * Alternatively, you can embed a Julia file that setup your environment and dependencies and embed it **first**. + * Because files are evaluated in the order they are embedded, it will deterine the env for all the other files. + +## Debugging + +* Most error will come from incorrect type passed between Julia and Nim. Check function interface and return type first. + +* 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. + +* If you do not work with fixed version package for Julia, you are at risk of code breaking when packages are updated / upgraded. + + # License This project is released under MIT License. From 6626a6fce44d619e23db3e09710cdfd8a37dd83b Mon Sep 17 00:00:00 2001 From: Regis Caillaud <35006197+Clonkk@users.noreply.github.com> Date: Tue, 26 Mar 2024 23:22:28 +0100 Subject: [PATCH 2/3] added exit mention to readme.md --- readme.md | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/readme.md b/readme.md index 71b20b9..1e0e407 100644 --- a/readme.md +++ b/readme.md @@ -72,16 +72,23 @@ Mostly quality-of-life improvements, especially when handling arrays. Here is the basic example: ```nim import nimjl +proc main() = + Julia.init() # Initialize Julia VM. Subsequent call will be ignored + + var myval = 4.0'f64 + # Call Julia function "sqrt" and convert the result to a float + var res = Julia.sqrt(myval).to(float64) + echo res # 2.0 -Julia.init() # Initialize Julia VM. Subsequent call will be ignored - -var myval = 4.0'f64 -# Call Julia function "sqrt" and convert the result to a float -var res = Julia.sqrt(myval).to(float64) -echo res # 2.0 +when isMainModule: + main() ``` +JlVmExit() seems optionnal. It's present in the C API but not calling it doesn't seem to cause any problem. + +Nonetheless, if you use OS resources from Julia it is probably better to call Julia.exit() / JlVmExit() for a clean exit. + ## Setting up Julia dependency * 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**. From 32a2f82724382c2618a34642bbfb325deaff9f8c Mon Sep 17 00:00:00 2001 From: Regis Caillaud <35006197+Clonkk@users.noreply.github.com> Date: Tue, 26 Mar 2024 23:22:54 +0100 Subject: [PATCH 3/3] Update nimjl.nimble --- nimjl.nimble | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nimjl.nimble b/nimjl.nimble index b7a9ced..2e7eea6 100644 --- a/nimjl.nimble +++ b/nimjl.nimble @@ -1,6 +1,6 @@ # Nimjl # Licensed and distributed under MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT). -version = "0.8.0" +version = "0.8.2" author = "Regis Caillaud" description = "Nim Julia bridge" license = "MIT"