You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: bring library to feature parity with libextism v1.9.0 (#112)
Fixesdylibso/xtp#955
This updates the sample apps to use the latest libextism version
- [x] CompiledPlugin
- [x] Fuel limit support
- [x] HTTP Response headers
- [x] Plugin Reset
- [x] Plugin ID access
- [x] Host Context in plugin calls
- [x] Update docs
Questions:
1. Do we need a `extism_compiled_plugin_new_error_free` function
(similar to `extism_plugin_new_error_free`)?
2. Did we cahnge how we're representing/reading f32/f64 values?
3. ~~Breaking changes to `CurrentPlugin.UserData`~~
Copy file name to clipboardExpand all lines: README.md
+166-4Lines changed: 166 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -79,6 +79,55 @@ printfn "%s" output
79
79
80
80
All exports have a simple interface of optional bytes in, and optional bytes out. This plug-in happens to take a string and return a JSON encoded string with a report of results.
81
81
82
+
## Precompiling plugins
83
+
84
+
If you're going to create more than one instance of the same plugin, we recommend pre-compiling the plugin and instantiate them:
| CompiledPluginInstantiate | 266.2 ms | 6.66 ms | 19.11 ms |
126
+
| PluginInstantiate | 27,592.4 ms | 635.90 ms | 1,783.12 ms |
127
+
```
128
+
129
+
*: See [the complete benchmark](./test/Extism.Sdk.Benchmarks/Program.cs)
130
+
82
131
### Plug-in State
83
132
84
133
Plug-ins may be stateful or stateless. Plug-ins can maintain state b/w calls by the use of variables. Our count vowels plug-in remembers the total number of vowels it's ever counted in the "total" key in the result. You can see this by making subsequent calls to the export:
@@ -193,7 +242,7 @@ var kvStore = new Dictionary<string, byte[]>();
Extism provides two ways to pass context to host functions:
338
+
339
+
### UserData
340
+
UserData allows you to associate persistent state with a host function that remains available across all calls to that function. This is useful for maintaining configuration or state that should be available throughout the lifetime of the host function.
341
+
342
+
C#:
343
+
344
+
```csharp
345
+
varhostFunc=newHostFunction(
346
+
"hello_world",
347
+
new[] { ExtismValType.PTR },
348
+
new[] { ExtismValType.PTR },
349
+
"Hello again!", // <= userData, this can be any .NET object
The userData object is preserved for the lifetime of the host function and can be retrieved in any call using `CurrentPlugin.GetUserData<T>()`. If no userData was provided, `GetUserData<T>()` will return the default value for type `T`.
374
+
375
+
### Call Host Context
376
+
377
+
Call Host Context provides a way to pass per-call context data when invoking a plugin function. This is useful when you need to provide data specific to a particular function call rather than data that persists across all calls.
let result = plugin.CallWithHostContext("function_name", inputData, context)
402
+
403
+
// Access context in host function
404
+
let hostFunction (plugin: CurrentPlugin) (inputs: Span<ExtismVal>) (outputs: Span<ExtismVal>) =
405
+
match plugin.GetCallHostContext<IDictionary<string, obj>>() with
406
+
| null -> printfn "No context available"
407
+
| context ->
408
+
let requestId = context.["requestId"] :?> int
409
+
printfn "Request ID: %d" requestId
410
+
```
411
+
412
+
Host context is only available for the duration of the specific function call and can be retrieved using `CurrentPlugin.GetHostContext<T>()`. If no context was provided for the call, `GetHostContext<T>()` will return the default value for type `T`.
413
+
414
+
## Fuel limit
415
+
416
+
The fuel limit feature allows you to constrain plugin execution by limiting the number of instructions it can execute. This provides a safeguard against infinite loops or excessive resource consumption.
417
+
418
+
### Setting a fuel limit
419
+
420
+
Set the fuel limit when initializing a plugin:
421
+
422
+
C#:
423
+
424
+
```csharp
425
+
varmanifest=newManifest(...);
426
+
varoptions=newPluginIntializationOptions {
427
+
FuelLimit=1000, // plugin can execute 1000 instructions
0 commit comments