OK, thanks for the clarification and explanations! I'll go for the second 
option you described then.

On Thursday, September 15, 2016 at 12:33:22 AM UTC+2, Yichao Yu wrote:
>
> On Wed, Sep 14, 2016 at 4:12 PM, Harald Held <haral...@gmail.com 
> <javascript:>> wrote: 
> > I'm playing around with embedding Julia in a C application and figured 
> out 
> > how to create and set scalars, arrays, and tuples from C successfully. 
> > 
> > What's missing for what I'm trying to do is to create a dictionary in C 
> that 
> > is then set to a Julia variable and used in a Julia script. However, I 
> > couldn't find any information on how to achieve that. Is that even 
> possible? 
> > If so, what is the appropriate type in C to allocate? 
>
> Dict is not a builtin type. It's just a normal julia type that doesn't 
> have a good mapping in C so there's no builtin API for it. 
> When dealing with such types for embedding, your options are, 
>
> 1. If you want to rely on the internal implementation detail of the 
> type, you can declare type in C with the same field as they appear in 
> julia code and manipulate the fields. (You probably don't want to use 
> Dict this way) 
> 2. Call julia functions to create/manipulate the object. This can 
> either be done by getting the function object and calling them with 
> `jl_apply` or `jl_call*` functions, or by getting a C callable 
> function pointer with `cfunction` julia function or `jl_function_ptr` 
> C API. This is the preferred option for handling complex objects like 
> dict. 
>
> > I guess I could just create two arrays (one holding the keys, the other 
> the 
> > values), zip them, and create a Dict from that result (in Julia code!) 
> -- 
> > but that would not be a pure C solution which I would prefer. 
>
> It's hard to say what counts as "pure C solution" since the object you 
> want to handle is implemented in pure julia. Unless you want to 
> reimplement it in pure C there's no pure C solution. 
>
> > 
> > Thanks for any hints and advice on that issue! 
>

Reply via email to