Comments (3)
How should I be setting up a jluna usertype for something I already have a Julia side type for?
Should I be making an equivalent type through the jluna usertype system and doing conversions Julia side (or using multiple dispatch when possible)? Or could I somehow link my jluna usertype to the existing Julia side struct?
Don't, if you already have a Julia-side type there is no point to using jluna::usertype. I think you misunderstood its purpose, it is specifically meant to create a not-yet-existing Julia-side type and make easy conversion possible in the C++ -> Julia direction. Everything else you should custom define.
If you already have a Julia-side type, simply write a wrapper like so:
# in julia
struct JuliaSideType
member::Any
JuliaSideType() = new(nothing)
end
julia_side_type_method(x::JuliaSideType) = println("do something");
// in cpp
class JuliaSideTypeWrapper
{
public:
// attach existing Julia-side value
JuliaSideTypeWrapper(jluna::Proxy& in)
: _value(in)
{
static auto* julia_side_type_type = Main["JuliaSideType"];
assert(in.isa(julia_side_type_type));
}
// newly allocate Julia-side instance
JuliaSideTypeWrapper()
{
static auto new_julia_side_type = Main["JuliaSideType"];
in = new_julia_side_type();
}
// allow for use with other proxy functions by allowing implicit conversion
operator jluna::unsafe::Value*()
{
return in.operator unsafe::Value*();
}
// wrap method
void julia_side_type_method()
{
jluna::Main["julia_side_type_method"](_value);
}
private:
jluna::Proxy _value;
}
(example untested, it's just to illustrate the design pattern)
from jluna.
Can I use a usertype in another usertype? Is there anything I need to do to make that possible?
Currently getting the following error when trying to build the example below: In template: no member named 'type_name' in 'jluna::detail::as_julia_type_aux'
You can, add the following before the declaration of JlunaHeader
:
namespace jluna::detail
{
template<>
struct as_julia_type_aux<JlunaStamp>
{
static inline const std::string type_name = "JlunaStamp";
};
}
It adds a case to the template meta function jluna::detail::as_julia_type_aux
so it works, It's mentioned in the error but I also realize that template meta functions aren't a very accessible thing, so I might make a macro for this since the error isn't very descriptive.
from jluna.
Rather than pasting the above mentioned code, you can now call make_usertype_implicitly_convertible(JlunaStamp)
once #37 is merged.
from jluna.
Related Issues (20)
- Confusion about how sleeping main thread affects task execution HOT 5
- jl_set_global going away HOT 2
- Usertype<T>::implement not respecting module argument HOT 1
- Warnings generated HOT 7
- Installation Issue with MinGW_64 HOT 12
- Julia and multi-threading HOT 2
- Thread adoption HOT 2
- Build Error on M1 MacBook Pro HOT 7
- Docker + JLuna HOT 2
- EXCEPTION_ACCESS_VIOLATION Windows 10 Visual Studio 2022 HOT 11
- Issues compiling on Mac HOT 3
- Array index on a 2D matrix not correct HOT 2
- Multi-threading example is not multi-threading HOT 2
- Error unsolved after troubleshooting: concept does not name a type HOT 8
- Installation failed on Ubuntu 22.04 with Julia 1.10.0-beta3 HOT 4
- Does Jluna support `import/using` registered packages? HOT 1
- Idea: Use a manager thread to support full C++ multi-threading
- I got an error of "Unable to load dependent library C:\soft_using\julia-1.9.4\bin\../bin/libjulia-codegen.dll"
- Apple aarch64 Compiler Error, unable to compile jluna HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jluna.