-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add wrap_module function to allow adding Julia code to a module
- Loading branch information
Showing
7 changed files
with
90 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <string> | ||
|
||
#include <cxx_wrap.hpp> | ||
|
||
namespace extended | ||
{ | ||
|
||
struct ExtendedWorld | ||
{ | ||
ExtendedWorld(const std::string& message = "default hello") : msg(message){} | ||
std::string greet() { return msg; } | ||
std::string msg; | ||
}; | ||
|
||
} // namespace extended | ||
|
||
JULIA_CPP_MODULE_BEGIN(registry) | ||
using namespace extended; | ||
|
||
cxx_wrap::Module& types = registry.create_module("ExtendedTypes"); | ||
|
||
types.add_type<ExtendedWorld>("ExtendedWorld") | ||
.method("greet", &ExtendedWorld::greet); | ||
|
||
JULIA_CPP_MODULE_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Example on how to load types and methods from C++ into an existing module | ||
|
||
println("Running extended_module.jl...") | ||
using Base.Test | ||
|
||
module ExtendedTypes | ||
|
||
using CxxWrap | ||
|
||
wrap_module(joinpath(Pkg.dir("CxxWrap"),"deps","usr","lib","libextended")) | ||
|
||
export ExtendedWorld, greet | ||
|
||
end | ||
|
||
using ExtendedTypes | ||
|
||
w = ExtendedWorld() | ||
@test greet(w) == "default hello" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters