Open gardhr opened 7 years ago
Ah, it's the docs. Had I not turned off warnings I would have spotted the problem right away too: I was passing a pointer to a function with the wrong signature! This example runs just fine:
#include "v7.h"
static enum v7_err
js_get_1024(struct v7 *v7, v7_val_t *res)
{
*res = v7_mk_number(v7, 1024);
return V7_OK;
}
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 = V7_INTERNAL_ERROR;
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: %s\n", (enum v7_err)result == V7_OK ? "success" : "failure");
v7_destroy(v7);
return (int)status;
}
Output:
get_1024: 1024 result: success
I've put in a pull request with corrections to the examples.
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:
The output of the program is:
Program was compiled with GCC 6.2.1:
Any ideas as to what's going on?