#define EXTISM_NO_JSON #include "extism.hpp" #include #include #include using namespace extism; std::vector read(const char *filename) { std::ifstream file(filename, std::ios::binary); return std::vector((std::istreambuf_iterator(file)), std::istreambuf_iterator()); } int main(int argc, char *argv[]) { auto wasm = read("../wasm/code-functions.wasm"); std::string tmp = "Testing"; // A lambda can be used as a host function auto hello_world = [&tmp](CurrentPlugin plugin, const std::vector &inputs, std::vector &outputs, void *user_data) { std::cout << "Hello from C++" << std::endl; std::cout << (const char *)user_data << std::endl; std::cout << tmp << std::endl; outputs[0].v = inputs[0].v; }; std::vector functions = { Function("hello_world", {ValType::I64}, {ValType::I64}, hello_world, (void *)"Hello again!", [](void *x) { std::cout << "Free user data" << std::endl; }), }; Plugin plugin(wasm, true, functions); const char *input = argc > 1 ? argv[1] : "this is a test"; ExtismSize length = strlen(input); extism::Buffer output = plugin.call("count_vowels", (uint8_t *)input, length); std::cout << (char *)output.data << std::endl; return 0; }