Clemapfel / jluna

Julia Wrapper for C++ with Focus on Safety, Elegance, and Ease of Use
https://clemens-cords.com/jluna
MIT License
246 stars 12 forks source link

Does Jluna support `import/using` registered packages? #60

Closed liuyxpp closed 10 months ago

liuyxpp commented 11 months ago

If so, how does it find the package? Can I specify which environment should Jluna look for packages? For any serious Julia app, using external packages is critical.

Clemapfel commented 10 months ago

Sorry for the late reply, import/using works exacty as it would in the REPL, you can either import a package using the safe_eval feature:

Main.safe_eval("import Pkg; Pkg.add(\"Makie\"));

Or use the specially designed Module::import and Module::add_using functions.

Main.import("Pkg");
Main.safe_eval("Pkg.add(\"Makie\")");

In both these examples, Julia will import the Pkg module into Main scope, then install Makie globally, meaning on your computer. If you run Julia in a way separate from jluna, Makie will still be installed.

Which module the import happens in depends on which C++-side jluna::Module object you use. In terms of finding the julia packages, that mechanism is identical to that of the REPL.

jlunas interface is basically just a programmatically operated REPL, anything that works there works in jluna.

Thank you