GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — cpp-sdk/example.cpp at main · extism/cpp-sdk Expand file tree/ Copy pathexample.cppMore file actions 48 lines (38 loc) · 1.39 KB / Copy pathexample.cppFile metadata and controls48 lines (38 loc) · 1.39 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 #define EXTISM_NO_JSON #include "extism.hpp" #include <cstring> #include <fstream> #include <iostream> using namespace extism; std::vector<uint8_t> read(const char *filename) { std::ifstream file(filename, std::ios::binary); return std::vector<uint8_t>((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>()); } int main(int argc, char *argv[]) { if (argc < 2) { std::cout << "No input file provided" << std::endl; return 1; } auto wasm = read(argv[1]); std::string tmp = "Testing"; // A lambda can be used as a host function auto hello_world = [&tmp](CurrentPlugin plugin, void *user_data) { std::cout << "Hello from C++" << std::endl; std::cout << (const char *)user_data << std::endl; std::cout << tmp << std::endl; plugin.outputVal(0).v = plugin.inputVal(0).v; }; std::vector<Function> functions = { Function("hello_world", {ValType::ExtismValType_I64}, {ValType::ExtismValType_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"; size_t length = strlen(input); extism::Buffer output = plugin.call("count_vowels", (uint8_t *)input, length); std::cout << (char *)output.data << std::endl; return 0; } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |