Skip to content

Commit

Permalink
Add test using julia_call on a struct
Browse files Browse the repository at this point in the history
  • Loading branch information
barche committed Sep 11, 2016
1 parent 83e4f57 commit 9711b4d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
16 changes: 16 additions & 0 deletions deps/src/examples/types.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <string>

#include <cxx_wrap.hpp>
#include <functions.hpp>

namespace cpp_types
{
Expand Down Expand Up @@ -97,6 +98,19 @@ struct ConstPtrConstruct
const World* m_w;
};

// Call a function on a type that is defined in Julia
struct JuliaTestType {
double a;
double b;
};
void call_testype_function()
{
JuliaTestType A = {2., 3.};
jl_value_t* result = jl_new_struct_uninit(cxx_wrap::julia_type("JuliaTestType"));
*reinterpret_cast<JuliaTestType*>(result) = A;
cxx_wrap::julia_call(cxx_wrap::julia_function("julia_test_func"), result);
}

} // namespace cpp_types

namespace cxx_wrap
Expand All @@ -110,6 +124,8 @@ JULIA_CPP_MODULE_BEGIN(registry)

cxx_wrap::Module& types = registry.create_module("CppTypes");

types.method("call_testype_function", call_testype_function);

types.add_type<DoubleData>("DoubleData");

types.add_type<World>("World")
Expand Down
13 changes: 13 additions & 0 deletions test/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,16 @@ println("created bc")

call_op = CallOperator()
@test call_op() == 43

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.
end

CppTypes.call_testype_function()

0 comments on commit 9711b4d

Please sign in to comment.