Skip to content

Instantly share code, notes, and snippets.

@peteristhegreat
Created February 24, 2020 22:58
Show Gist options
  • Save peteristhegreat/0058065c3cf0c5c9037e491e8c50ff8e to your computer and use it in GitHub Desktop.
Save peteristhegreat/0058065c3cf0c5c9037e491e8c50ff8e to your computer and use it in GitHub Desktop.
Convert argc, argv to julia Vector{Any}() aka Array of Strings, julia embedding, c, cpp, char**, jl_pchar_to_string,
// int main( int argc, char *argv[] )
// {
// julia_ensure_init();
jl_array_t * args_array_jl = jl_alloc_vec_any(argc - 1);
void **data = (void**)jl_array_data(args_array_jl);
jl_gc_enable(0);
for(int i = 1; i < argc; i++){
jl_value_t * arg_str_jl = jl_pchar_to_string((char*)argv[i], strlen(argv[i]));
data[i - 1] = arg_str_jl;
}
jl_gc_enable(1);
jl_value_t * retVal = jl_call1(main_func, (jl_value_t *) args_array_jl);
if(julia_exception()){
return -999;
}
long ret_unboxed = (long) jl_unbox_int64(retVal);
jl_atexit_hook(0);
// return 0;
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment