Skip to content

Problem running a basic test program #579

@gardhr

Description

@gardhr

I couldn't get the example shown in the docs to run properly (after fixing several syntax errors!), so I put together this simple test program:

#include "v7.h"

static v7_val_t
    js_get_1024(struct v7* v7, v7_val_t this_obj, v7_val_t args)
{
    (void)this_obj;
    (void)args;
    return v7_mk_number(v7, 1024);
}

int
    main(void)
{
    struct v7*
        v7 = v7_create();
    v7_set_method(v7, v7_get_global(v7), "get_1024", &js_get_1024);
    v7_val_t
        result = 0;
    enum v7_err
        status = v7_exec(v7, "print('get_1024: ' + get_1024())", &result);
    if(status != V7_OK)
        fprintf(stderr, "error: %d\n", (int)status);
    else
        printf("result: %f\n", (float)v7_get_double(v7, result));
    v7_destroy(v7);
    return (int)status;
}

The output of the program is:

get_1024: undefined
result: -nan

Program was compiled with GCC 6.2.1:

gcc -Wno-incompatible-pointer-types -lm -o test v7.c test.c

Any ideas as to what's going on?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions