Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

How to retrieve global variable in C

$
0
0

@nnn wrote:

I want to retrieve global variable x I just set in Julia from my C application.
Here’s the code I have so far:

#include <julia.h>

void SimpleExecute(char *command, char *resultVar, char* result) {

	jl_eval_string(command);

	jl_value_t *var = jl_get_global(jl_base_module, jl_symbol(resultVar));

	const char *str = jl_string_ptr(var);

	sprintf(result, "%s", str);
}

int main(int argc, char *argv[])
{
	char* result = malloc(sizeof(char) * 1024);

    jl_init();

    //(void)jl_eval_string("println(sqrt(2.0))"); //works
    (void)SimpleExecute("x=sqrt(2.0)", "x", result);

    jl_atexit_hook(0);
    return 0;
}

However debugger shows that var is still NULL after jl_get_global call. Why?
I followed this tutorial but it does not touch on arbitrary variable retrieval.

enter image description here

Posts: 5

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 2795

Trending Articles