feat: add extism_plugin_update (#6)

This gives host the ability to re-use plugin descriptors instead of
loading a new plugin each time. The plugin memory and everything is
reset, so no state is shared with the newly loaded plugin.

Co-authored-by: Steve Manuel <steve@dylib.so>
This commit is contained in:
zach
2022-09-08 16:37:34 -07:00
committed by Steve Manuel
parent 4fa8030a64
commit 7b27d4f883
27 changed files with 799 additions and 425 deletions

View File

@@ -6,6 +6,7 @@ const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
let _functions = {
extism_plugin_register: ['int32', ['string', 'uint64', 'bool']],
extism_plugin_update: ['bool', ['int32', 'string', 'uint64', 'bool']],
extism_error: ['char*', ['int32']],
extism_call: ['int32', ['int32', 'string', 'string', 'uint64']],
extism_output_length: ['uint64', ['int32']],
@@ -59,6 +60,23 @@ export class Plugin {
}
}
update(data, wasi = false, config = null) {
if (typeof data === "object" && data.wasm) {
data = JSON.stringify(data);
}
const ok = lib.extism_plugin_update(this.id, data, data.length, wasi);
if (!ok) {
return false;
}
if (config != null) {
let s = JSON.stringify(config);
lib.extism_plugin_config(this.id, s, s.length);
}
return true;
}
call(name, input) {
var rc = lib.extism_call(this.id, name, input, input.length);
if (rc != 0) {