Thanks so much for the guide, Bart. Will study.
On Monday, September 12, 2016 at 5:18:52 AM UTC+8, Bart Janssens wrote: > > On Sun, Sep 11, 2016 at 2:47 AM K leo <cnbi...@gmail.com <javascript:>> > wrote: > >> Hi Bart, >> >> These are meant to call Julia code from C++. You mentioned "there may be >> easier ways using Cxx.jl or CxxWrap.jl". Are the two packages only for >> calling C/C++ from Julia, and not the otherway around? Am I missing >> something? >> >> > Yes, both are initialized from Julia. So you would use them to start your > C++ framework, but then you can call back into Julia from there (you don't > need the jl_init stuff then, a nice bonus). I've added a test replicating > your example to CxxWrap.jl: > > https://github.com/barche/CxxWrap.jl/commit/9711b4d6baca99c2c30280d197bba3168167ed59 > > In Cxx.jl, as Keno said you can implement a C++ (member) function using > Julia code, like this for example: > > using Cxx > using Base.Test > > type JuliaTestType > a::Float64 > b::Float64 > end > > function julia_test_func(data) > println("a: ", data.a, ", b: ", data.b) > @test data.a == 2. > @test data.b == 3. > nothing > end > > # Declare a C++ class > cxx""" > class CppClass { > public: > void call_julia(); > }; > """ > > # Implement member function in Julia > @cxxm "void CppClass::call_julia()" begin > A = JuliaTestType(2.,3.) > julia_test_func(A) > end > > # Call C++ function > icxx""" > CppClass a; > a.call_julia(); > """ > >