From da1d8459be7526331da63eafcedb84a213c58dba Mon Sep 17 00:00:00 2001 From: mike dupont Date: Sat, 9 Dec 2023 09:47:55 -0500 Subject: [PATCH] dont forget the code --- plugin_nodejs_metacall.cpp | 117 +++++++++++++++++++++++++++++++++++++ plugin_nodejs_metacall.hpp | 6 ++ 2 files changed, 123 insertions(+) create mode 100644 plugin_nodejs_metacall.cpp create mode 100644 plugin_nodejs_metacall.hpp diff --git a/plugin_nodejs_metacall.cpp b/plugin_nodejs_metacall.cpp new file mode 100644 index 0000000000000..a66ea9bdb99ae --- /dev/null +++ b/plugin_nodejs_metacall.cpp @@ -0,0 +1,117 @@ +#include +#include +#include +#include +#include + +int sum(double a, double b) +{ + // Parameters to be passed to the sum function + void * args[] = + { + metacall_value_create_double(a), metacall_value_create_double(b) + }; + + void * ret = NULL; + + // Call to sum function + ret = metacallv("sum", args); + + // Clean up arguments + for (size_t it = 0; it < sizeof(args) / sizeof(args[0]); ++it) + { + metacall_value_destroy(args[it]); + } + + if (ret == NULL) + { + printf("Function sum returned: NULL\n"); + return 1; + } + + printf("Function sum returned: %f\n", metacall_value_to_double(ret)); + + // Clean up return value + metacall_value_destroy(ret); + + return 0; +} + +class Context { +public: + + struct metacall_log_stdio_type log_stdio = { stdout }; + void* handle = NULL; // function pointer +}; + +static Context context; + +void process_output_plugin_metacall_init() +{ + + + printf(metacall_print_info()); + + // Define log stream + if (metacall_log(METACALL_LOG_STDIO, (void *)&context.log_stdio) != 0) + { + //return cleanup(1); + } + + // Initialize MetaCall + if (metacall_initialize() != 0) + { + //return cleanup(2); + } + + // Array of scripts to be loaded by MetaCall + const char * js_scripts[] = + { + "script.js" + }; + + + + // Load scripts + if (metacall_load_from_file("node", + js_scripts, + sizeof(js_scripts) / sizeof(js_scripts[0]), &context.handle) != 0) + { + //return cleanup(3); + //return "error loading"; + } + +} + + +std::string process_output_plugin_metacall(const std::string start, + const std::string state, + const std::string input) { + + // NodeJS + + // Execute sum function + if (sum(3, 4) != 0) + { + return "error executing"; + } + + + + + return "OK"; + +} + + +void process_output_plugin_metacall_destroy() +{ + + metacall_clear(context.handle); + //if ( + metacall_destroy(); + //!= 0) + //{ + //return code != 0 ? -code : -255; + // } +} diff --git a/plugin_nodejs_metacall.hpp b/plugin_nodejs_metacall.hpp new file mode 100644 index 0000000000000..bda5b5ea0203a --- /dev/null +++ b/plugin_nodejs_metacall.hpp @@ -0,0 +1,6 @@ +void process_output_plugin_metacall_init(); +void process_output_plugin_metacall_destroy(); + +std::string process_output_plugin_metacall(const std::string start, + const std::string state, + const std::string input);