Class HostFunction
A function provided by the host that plugins can call.
public class HostFunction : IDisposable
- Inheritance
-
HostFunction
- Implements
- Inherited Members
Constructors
HostFunction(string, Span<ExtismValType>, Span<ExtismValType>, nint, ExtismFunction)
Registers a Host Function.
public HostFunction(string functionName, Span<ExtismValType> inputTypes, Span<ExtismValType> outputTypes, nint userData, ExtismFunction hostFunction)
Parameters
functionName
stringThe literal name of the function, how it would be called from a Plugin.
inputTypes
Span<ExtismValType>The types of the input arguments/parameters the Plugin caller will provide.
outputTypes
Span<ExtismValType>The types of the output returned from the host function to the Plugin.
userData
nintAn opaque pointer to an object from the host, accessible on CurrentPlugin. NOTE: it is the shared responsibility of the host and Plugin to cast/dereference this value properly.
hostFunction
ExtismFunction
Methods
CheckNotDisposed()
Throw an appropriate exception if the Host Function has been disposed.
protected void CheckNotDisposed()
Exceptions
Dispose()
Frees all resources held by this Host Function.
public void Dispose()
Dispose(bool)
Frees all resources held by this Host Function.
protected virtual void Dispose(bool disposing)
Parameters
disposing
bool
~HostFunction()
Destructs the current Host Function and frees all resources used by it.
protected ~HostFunction()
FromMethod(string, nint, Action<CurrentPlugin>)
Registers a HostFunction from a method that takes no parameters an returns no values.
public static HostFunction FromMethod(string functionName, nint userdata, Action<CurrentPlugin> callback)
Parameters
functionName
stringThe literal name of the function, how it would be called from a Plugin.
userdata
nintAn opaque pointer to an object from the host, accessible on CurrentPlugin. NOTE: it is the shared responsibility of the host and Plugin to cast/dereference this value properly.
callback
Action<CurrentPlugin>The host function implementation.
Returns
FromMethod<I1>(string, nint, Action<CurrentPlugin, I1>)
Registers a HostFunction from a method that takes 1 parameter an returns no values. Supported parameter types: int, uint, long, ulong, float, double
public static HostFunction FromMethod<I1>(string functionName, nint userdata, Action<CurrentPlugin, I1> callback) where I1 : struct
Parameters
functionName
stringThe literal name of the function, how it would be called from a Plugin.
userdata
nintAn opaque pointer to an object from the host, accessible on CurrentPlugin. NOTE: it is the shared responsibility of the host and Plugin to cast/dereference this value properly.
callback
Action<CurrentPlugin, I1>The host function implementation.
Returns
Type Parameters
FromMethod<R>(string, nint, Func<CurrentPlugin, R>)
Registers a HostFunction from a method that takes no parameters an returns a value. Supported return types: int, uint, long, ulong, float, double
public static HostFunction FromMethod<R>(string functionName, nint userdata, Func<CurrentPlugin, R> callback) where R : struct
Parameters
functionName
stringThe literal name of the function, how it would be called from a Plugin.
userdata
nintAn opaque pointer to an object from the host, accessible on CurrentPlugin. NOTE: it is the shared responsibility of the host and Plugin to cast/dereference this value properly.
callback
Func<CurrentPlugin, R>The host function implementation.
Returns
Type Parameters
FromMethod<I1, I2>(string, nint, Action<CurrentPlugin, I1, I2>)
Registers a HostFunction from a method that takes 2 parameters an returns no values. Supported parameter types: int, uint, long, ulong, float, double
public static HostFunction FromMethod<I1, I2>(string functionName, nint userdata, Action<CurrentPlugin, I1, I2> callback) where I1 : struct where I2 : struct
Parameters
functionName
stringThe literal name of the function, how it would be called from a Plugin.
userdata
nintAn opaque pointer to an object from the host, accessible on CurrentPlugin. NOTE: it is the shared responsibility of the host and Plugin to cast/dereference this value properly.
callback
Action<CurrentPlugin, I1, I2>The host function implementation.
Returns
Type Parameters
I1
Type of the first parameter. Supported parameter types: int, uint, long, ulong, float, double
I2
Type of the second parameter. Supported parameter types: int, uint, long, ulong, float, double
FromMethod<I1, R>(string, nint, Func<CurrentPlugin, I1, R>)
Registers a HostFunction from a method that takes 1 parameter an returns a value. Supported return and parameter types: int, uint, long, ulong, float, double
public static HostFunction FromMethod<I1, R>(string functionName, nint userdata, Func<CurrentPlugin, I1, R> callback) where I1 : struct where R : struct
Parameters
functionName
stringThe literal name of the function, how it would be called from a Plugin.
userdata
nintAn opaque pointer to an object from the host, accessible on CurrentPlugin. NOTE: it is the shared responsibility of the host and Plugin to cast/dereference this value properly.
callback
Func<CurrentPlugin, I1, R>The host function implementation.
Returns
Type Parameters
I1
Type of the first parameter. Supported parameter types: int, uint, long, ulong, float, double
R
Type of the first parameter. Supported parameter types: int, uint, long, ulong, float, double
FromMethod<I1, I2, I3>(string, nint, Action<CurrentPlugin, I1, I2, I3>)
Registers a HostFunction from a method that takes 3 parameters an returns no values. Supported parameter types: int, uint, long, ulong, float, double
public static HostFunction FromMethod<I1, I2, I3>(string functionName, nint userdata, Action<CurrentPlugin, I1, I2, I3> callback) where I1 : struct where I2 : struct where I3 : struct
Parameters
functionName
stringThe literal name of the function, how it would be called from a Plugin.
userdata
nintAn opaque pointer to an object from the host, accessible on CurrentPlugin. NOTE: it is the shared responsibility of the host and Plugin to cast/dereference this value properly.
callback
Action<CurrentPlugin, I1, I2, I3>The host function implementation.
Returns
Type Parameters
I1
Type of the first parameter. Supported parameter types: int, uint, long, ulong, float, double
I2
Type of the second parameter. Supported parameter types: int, uint, long, ulong, float, double
I3
Type of the third parameter. Supported parameter types: int, uint, long, ulong, float, double
FromMethod<I1, I2, R>(string, nint, Func<CurrentPlugin, I1, I2, R>)
Registers a HostFunction from a method that takes 2 parameter an returns a value. Supported return and parameter types: int, uint, long, ulong, float, double
public static HostFunction FromMethod<I1, I2, R>(string functionName, nint userdata, Func<CurrentPlugin, I1, I2, R> callback) where I1 : struct where I2 : struct where R : struct
Parameters
functionName
stringThe literal name of the function, how it would be called from a Plugin.
userdata
nintAn opaque pointer to an object from the host, accessible on CurrentPlugin. NOTE: it is the shared responsibility of the host and Plugin to cast/dereference this value properly.
callback
Func<CurrentPlugin, I1, I2, R>The host function implementation.
Returns
Type Parameters
I1
Type of the first parameter. Supported parameter types: int, uint, long, ulong, float, double
I2
Type of the second parameter. Supported parameter types: int, uint, long, ulong, float, double
R
Type of the first parameter. Supported parameter types: int, uint, long, ulong, float, double
FromMethod<I1, I2, I3, R>(string, nint, Func<CurrentPlugin, I1, I2, I3, R>)
Registers a HostFunction from a method that takes 3 parameter an returns a value. Supported return and parameter types: int, uint, long, ulong, float, double
public static HostFunction FromMethod<I1, I2, I3, R>(string functionName, nint userdata, Func<CurrentPlugin, I1, I2, I3, R> callback) where I1 : struct where I2 : struct where I3 : struct where R : struct
Parameters
functionName
stringThe literal name of the function, how it would be called from a Plugin.
userdata
nintAn opaque pointer to an object from the host, accessible on CurrentPlugin. NOTE: it is the shared responsibility of the host and Plugin to cast/dereference this value properly.
callback
Func<CurrentPlugin, I1, I2, I3, R>The host function implementation.
Returns
Type Parameters
I1
Type of the first parameter. Supported parameter types: int, uint, long, ulong, float, double
I2
Type of the second parameter. Supported parameter types: int, uint, long, ulong, float, double
I3
Type of the third parameter. Supported parameter types: int, uint, long, ulong, float, double
R
Type of the first parameter. Supported parameter types: int, uint, long, ulong, float, double
SetNamespace(string)
Sets the function namespace. By default it's set to env
.
public void SetNamespace(string ns)
Parameters
ns
string
WithNamespace(string)
Sets the function namespace. By default it's set to extism:host/user
.
public HostFunction WithNamespace(string ns)
Parameters
ns
string