Table of Contents

Class HostFunction

Namespace
Extism.Sdk
Assembly
Extism.Sdk.dll

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>, object?, ExtismFunction)

Registers a Host Function.

public HostFunction(string functionName, Span<ExtismValType> inputTypes, Span<ExtismValType> outputTypes, object? userData, ExtismFunction hostFunction)

Parameters

functionName string

The 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 object

A state object that will be preserved and can be retrieved during function execution using GetUserData<T>(). This allows you to maintain context between function calls.

hostFunction ExtismFunction

Methods

CheckNotDisposed()

Throw an appropriate exception if the Host Function has been disposed.

protected void CheckNotDisposed()

Exceptions

ObjectDisposedException

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, object, Action<CurrentPlugin>)

Registers a HostFunction from a method that takes no parameters an returns no values.

public static HostFunction FromMethod(string functionName, object userData, Action<CurrentPlugin> callback)

Parameters

functionName string

The literal name of the function, how it would be called from a Plugin.

userData object

A state object that will be preserved and can be retrieved during function execution using GetUserData<T>(). This allows you to maintain context between function calls.

callback Action<CurrentPlugin>

The host function implementation.

Returns

HostFunction

FromMethod<I1>(string, object, 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, object userData, Action<CurrentPlugin, I1> callback) where I1 : struct

Parameters

functionName string

The literal name of the function, how it would be called from a Plugin.

userData object

A state object that will be preserved and can be retrieved during function execution using GetUserData<T>(). This allows you to maintain context between function calls.

callback Action<CurrentPlugin, I1>

The host function implementation.

Returns

HostFunction

Type Parameters

I1

Type of first parameter. Supported parameter types: int, uint, long, ulong, float, double

FromMethod<R>(string, object, 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, object userData, Func<CurrentPlugin, R> callback) where R : struct

Parameters

functionName string

The literal name of the function, how it would be called from a Plugin.

userData object

A state object that will be preserved and can be retrieved during function execution using GetUserData<T>(). This allows you to maintain context between function calls.

callback Func<CurrentPlugin, R>

The host function implementation.

Returns

HostFunction

Type Parameters

R

Type of the first parameter. Supported parameter types: int, uint, long, ulong, float, double

FromMethod<I1, I2>(string, object, 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, object userData, Action<CurrentPlugin, I1, I2> callback) where I1 : struct where I2 : struct

Parameters

functionName string

The literal name of the function, how it would be called from a Plugin.

userData object

A state object that will be preserved and can be retrieved during function execution using GetUserData<T>(). This allows you to maintain context between function calls.

callback Action<CurrentPlugin, I1, I2>

The host function implementation.

Returns

HostFunction

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, object, 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, object userData, Func<CurrentPlugin, I1, R> callback) where I1 : struct where R : struct

Parameters

functionName string

The literal name of the function, how it would be called from a Plugin.

userData object

A state object that will be preserved and can be retrieved during function execution using GetUserData<T>(). This allows you to maintain context between function calls.

callback Func<CurrentPlugin, I1, R>

The host function implementation.

Returns

HostFunction

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, object, 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, object userData, Action<CurrentPlugin, I1, I2, I3> callback) where I1 : struct where I2 : struct where I3 : struct

Parameters

functionName string

The literal name of the function, how it would be called from a Plugin.

userData object

A state object that will be preserved and can be retrieved during function execution using GetUserData<T>(). This allows you to maintain context between function calls.

callback Action<CurrentPlugin, I1, I2, I3>

The host function implementation.

Returns

HostFunction

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, object, 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, object userData, Func<CurrentPlugin, I1, I2, R> callback) where I1 : struct where I2 : struct where R : struct

Parameters

functionName string

The literal name of the function, how it would be called from a Plugin.

userData object

A state object that will be preserved and can be retrieved during function execution using GetUserData<T>(). This allows you to maintain context between function calls.

callback Func<CurrentPlugin, I1, I2, R>

The host function implementation.

Returns

HostFunction

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, object, 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, object userData, Func<CurrentPlugin, I1, I2, I3, R> callback) where I1 : struct where I2 : struct where I3 : struct where R : struct

Parameters

functionName string

The literal name of the function, how it would be called from a Plugin.

userData object

A state object that will be preserved and can be retrieved during function execution using GetUserData<T>(). This allows you to maintain context between function calls.

callback Func<CurrentPlugin, I1, I2, I3, R>

The host function implementation.

Returns

HostFunction

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

Returns

HostFunction