Calling functions defined a custom module when embeded in C

hello julia hackers! Could you help me on calling functions defined a custom module in C?
I’ve tried:

jl_eval_string("using mymodule");
jl_function_t* func = jl_get_function(jl_main_module, "myfunction");

this works as expected. While

    jl_sym_t* sym = jl_symbol("mymodule");
    jl_module_t* mymod = jl_new_module(sym);
    jl_module_using(jl_main_module, mymod);
    jl_function_t* func = jl_get_function(jl_main_module, "myfunction");

always returns null. What’s the correct way to express ‘using mymodule’ in C functions?

I’m doing this on Windows7 MSVC 2015.

Julia Version 0.6.2
Commit d386e40c17* (2017-12-13 18:08 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i5-4570 CPU @ 3.20GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)

Thank you in advance.
pem

Won’t that simply create a new (empty) module?
The jl_module_using call will simply use that empty module, IIUC.

jl_eval_string("using mymodule") basically.

I don’t think there’s an API for it. There could be, though given how easy it is to construct this kind of API yourself it certainly won’t be a high priority.

Like pypy, the recommended way to use julia functions in julia is to make your own API. You can create a julia function using_module(name) = eval(:(using $name)) (e.g. with jl_eval_string) and just call that function in C. You can also construct the Expr (i.e. jl_expr_t*) and eval that.

1 Like