difftreelog
test extend bindings tests to include native methods
in: master
2 files changed
bindings/c/libjsonnet_test_file.cdiffbeforeafterboth161617#include "libjsonnet.h"17#include "libjsonnet.h"1819typedef struct JsonnetJsonValue* val_t;20typedef struct JsonnetVm* vm_t;2122typedef struct native_ctx_t {23 vm_t vm24} native_ctx_t;2526val_t native_add(void* nctx, const struct JsonnetJsonValue* const* argv, int* success) {27 native_ctx_t* ctx = nctx;28 double a;29 double b;30 jsonnet_json_extract_number(ctx->vm, argv[0], &a);31 jsonnet_json_extract_number(ctx->vm, argv[1], &b);32 *success = 1;33 return jsonnet_json_make_number(ctx->vm, a + b);34}183519int main(int argc, const char **argv)36int main(int argc, const char **argv)20{37{27 }44 }28 vm = jsonnet_make();45 vm = jsonnet_make();4647 native_ctx_t* native_ctx = malloc(sizeof(native_ctx_t));48 native_ctx->vm = vm;49 const char* params[3] = {"a", "b", NULL};50 jsonnet_native_callback(vm, "nativeAdd", native_add, native_ctx, params);5129 output = jsonnet_evaluate_file(vm, argv[1], &error);52 output = jsonnet_evaluate_file(vm, argv[1], &error);30 if (error) {53 if (error) {35 }58 }36 printf("%s", output);59 printf("%s", output);37 jsonnet_realloc(vm, output, 0);60 jsonnet_realloc(vm, output, 0);61 free(native_ctx);38 jsonnet_destroy(vm);62 jsonnet_destroy(vm);39 return EXIT_SUCCESS;63 return EXIT_SUCCESS;40}64}bindings/test.jsonnetdiffbeforeafterbothno changes