Yes, Jakes suggestion looks good. When I wrote the embedding doku I also 
played around with several internal functions and it turned out that 
jl_eval_string is very versatile and can be used in various circumstances.

Einar: Would be great if you could test it and improve the embedding 
documentation (on the github page) with an example how to get arbitrary 
module pointer.

Thanks

Tobi

Am Freitag, 5. September 2014 17:46:33 UTC+2 schrieb Jake Bolewski:
>
> It's jl_eval_string located in jl_api.c in src.
>
> so you would do
> jl_value_t * func2 = jl_eval_string("DSP.hanning")
>
> The best way to play around with Julia's c-api is within julia itself.
> julia> pkg_ptr = ccall(:jl_eval_string, Ptr{Void}, (Ptr{Cchar},), 
> "Base.Pkg.clone")
> Ptr{Void} @0x00007fd11c1754a0
>
> julia> unsafe_pointer_to_objref(ans)
> clone (generic function with 2 methods)
>
> julia> typeof(ans)
> Function
>
> That way you can prototype what you want much more easily.
>
> On Friday, September 5, 2014 9:32:43 AM UTC-4, Einar Otnes wrote:
>>
>> Thank you for your help on this. It seems that the 'jl_eval_global_var' 
>> function is local as I got the error "undefined reference to 
>> `jl_eval_global_var'" when linking. I replaced 
>> your suggestion with: 
>>
>>     jl_module_t* jl_dsp_module = (jl_module_t*) 
>> jl_get_binding(jl_main_module, jl_symbol("DSP"));
>>     jl_function_t* func2 = jl_get_function(jl_dsp_module,"hanning");
>>
>> This compiles OK, but I get a "segfault  (core dumped)" when running the 
>> line with 'jl_get_function' .
>>
>> Any ideas or thoughts?
>>
>> Thanks,
>>
>> Einar
>>
>>
>>
>>
>>
>>
>>
>>
>> On Fri, Sep 5, 2014 at 11:15 AM, Ivar Nesje <iva...@gmail.com> wrote:
>>
>>> I would guess that something like
>>>
>>> module = jl_eval_global_var 
>>> <https://github.com/JuliaLang/julia/blob/6277015ee3d46f20149136d092525bec95b6e29d/src/julia.h#L917>
>>> (jl_main_module, jl_sym 
>>> <https://github.com/JuliaLang/julia/blob/6277015ee3d46f20149136d092525bec95b6e29d/src/julia.h#L666>
>>> ("MyModule"))
>>>
>>> would work, but I don't have the required testing setup to see if it 
>>> actually works. (Where is my C REPL?) The embedding API has not gotten much 
>>> attention (yet), so it is mostly documented in source, and it is likely 
>>> that there will be some adjustments.
>>>
>>>
>>> On Friday, September 5, 2014 10:09:03 AM UTC+2, Einar Otnes wrote:
>>>>
>>>> Sorry, I'm a bit slow. How do I look up a binding for a specific 
>>>> module? In other words, how would I explicitly get to call the "fftfreq" 
>>>> function in the "DSP" module from C/C++?
>>>>
>>>> Is this this documented anywhere in Julia docs?
>>>>
>>>> Thanks,
>>>> Einar
>>>>
>>>>
>>>>
>>>> On Wednesday, September 3, 2014 3:10:59 PM UTC+2, Isaiah wrote:
>>>>>
>>>>> If you have defined a module already (by eval'ing julia code?) then 
>>>>> you can look up the binding and cast that to a jl_module_t.
>>>>> On Sep 3, 2014 8:14 AM, "Einar Otnes" <eot...@gmail.com> wrote:
>>>>>
>>>>>> Dear experts,
>>>>>>
>>>>>> I've looking at the documentation " Embedding Julia" (
>>>>>> http://julia.readthedocs.org/en/latest/manual/embedding/) to figure 
>>>>>> out how I can call my own julia functions from within C, and I'm 
>>>>>> struggling 
>>>>>> to figure out how I should define the jl_module_t that corresponds the 
>>>>>> module I've defined. The examples show that there is an instance of 
>>>>>> jl_module_t,  "jl_base_module",  that you need to provide to be able to 
>>>>>> call a function defined in the base module. How do I define a 
>>>>>> corresponding 
>>>>>> jl_module_t type for the modules that are defined outside of standard 
>>>>>> julia, e.g. for the external packages or the modules I have created 
>>>>>> myself?
>>>>>>
>>>>>> Thanks for your help.
>>>>>>
>>>>>> Best regards,
>>>>>>
>>>>>> Einar Otnes
>>>>>>
>>>>>>
>>

Reply via email to