mirror of
https://github.com/extism/extism.git
synced 2026-01-10 14:27:57 -05:00
- Adds `ExtismContext` instead of global `PLUGINS` registry - Adds `extism_context_new`, `extism_context_free` and `extism_context_reset` - Requires updating nearly every SDK function to add context parameter - Renames some SDK functions to follow better naming conventions - `extism_plugin_register` -> `extism_plugin_new` - `extism_output_get` -> `extism_plugin_output_data` - `extism_output_length` -> `extism_plugin_output_length` - `extism_call` -> `extism_plugin_call` - Updates `extism_error` to return the context error when -1 issued for the plug-in ID - Adds `extism_plugin_free` to remove an existing plugin - Updates SDKs to include these functions - Updates SDK examples and comments Co-authored-by: Steve Manuel <steve@dylib.so>
28 lines
737 B
C++
28 lines
737 B
C++
#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[]) {
|
|
auto wasm = read("../wasm/code.wasm");
|
|
Context context = Context();
|
|
|
|
Plugin plugin = context.plugin(wasm);
|
|
|
|
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;
|
|
}
|