summaryrefslogtreecommitdiffhomepage
path: root/examples/native-function.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/native-function.c')
-rw-r--r--examples/native-function.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/examples/native-function.c b/examples/native-function.c
index 9c643ec..5c2f6da 100644
--- a/examples/native-function.c
+++ b/examples/native-function.c
@@ -23,7 +23,7 @@
#define MULTILINE_STRING(...) #__VA_ARGS__
-static const char *program = MULTILINE_STRING(
+static const char *program_code = MULTILINE_STRING(
{%
print("add() = " + add(5, 3.1, 2) + "\n");
print("multiply() = " + multiply(7.3, 5) + "\n");
@@ -61,17 +61,17 @@ int main(int argc, char **argv)
int exit_code = 0;
/* create a source buffer containing the program code */
- uc_source_t *src = uc_source_new_buffer("my program", strdup(program), strlen(program));
+ uc_source_t *src = uc_source_new_buffer("my program", strdup(program_code), strlen(program_code));
/* compile source buffer into function */
char *syntax_error = NULL;
- uc_function_t *progfunc = uc_compile(&config, src, &syntax_error);
+ uc_program_t *program = uc_compile(&config, src, &syntax_error);
/* release source buffer */
uc_source_put(src);
/* check if compilation failed */
- if (!progfunc) {
+ if (!program) {
fprintf(stderr, "Failed to compile program: %s\n", syntax_error);
return 1;
@@ -89,7 +89,10 @@ int main(int argc, char **argv)
uc_function_register(uc_vm_scope_get(&vm), "multiply", multiply_two_numbers);
/* execute program function */
- int return_code = uc_vm_execute(&vm, progfunc, NULL);
+ int return_code = uc_vm_execute(&vm, program, NULL);
+
+ /* release program */
+ uc_program_put(program);
/* handle return status */
if (return_code == ERROR_COMPILE || return_code == ERROR_RUNTIME) {