mirror of
https://github.com/extism/extism.git
synced 2026-04-23 03:00:11 -04:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user