Available here: https://github.com/Clemapfel/jluna
(Edit: the license of the library has been changed to MIT, making it freely available without restrictions)
I have spend the last few months, full-time, writing a Julia ⭤ wrapper completely from scratch. It aims to fully replace the C-API in usage in C++ projects, and offers a possible alternative to Cxx.jl.
I aim for jluna to be…
- modern: uses the most modern C++20 features, the newest compiler versions and Julia 1.7+
-
generic: all
std::
C++ and C classes are wrapped, and can be move between Julia and C++ freely. Any Julia object can be moved to C++ or access and modified directly - safe: full exception forwarding from julia, compile-time assertions, safety from the garbage collector, etc.
- fast: as of version 0.7, jluna went through extensive optimization to reduce overhead compared to the C-API as much as possible
- elegant: generic syntax and modern design patterns make C++ syntax feel almost as nice as Julias
- well-documented: verbose documentation, a handwritten manual that introduces every feature step-by-step, installation guide, inline-documentation for IDEs
// execute arbitrary strings with exception forwarding
State::safe_script(R"(
f(x) = x*x*x
mutable struct MyStruct
_field
MyStruct() = new(123)
end
instance = MyStruct();
)");
// access and modify variables
Main["instance"]["_field"] = 456;
State::script(R"(println("instance._field is now: ", instance._field))");
// call julia-side functions with C++-side values
int result = Main["f"](12);
Base["println"](result);
/// muti-dimensional, 0-overhead array interface
State::script("jl_array = reshape(collect(1:9), 3, 3)");
Array<size_t, 2> cpp_array = Main["jl_array"];
// iterable and assignable
for (auto e : cpp_array)
e = e.operator size_t() + 10; // this also modified julia-side variable Main.jl_array
// julia-style, multi-dimensional indexing
cpp_array.at(1, 2);
// julia-style array comperehension
cpp_array.at({8, 2, 5, 6});
Even more exciting examples can be found on github!
Please consider checking it out, it is available for free under MIT license. I am proud of my work and I hope that some others may also find it useful or at least enjoyable.
Hidden bonus: jluna made C++ have list comprehension:
using namespace jluna;
for (size_t i : "(i for i in 1:10 if i % 2 == 0)"_gen)
std::cout << i << " ";
2 4 6 8 10