Table of Contents

Class CurrentPlugin

Namespace
Extism.Sdk
Assembly
Extism.Sdk.dll

Represents the current plugin. Can only be used within HostFunctions.

public class CurrentPlugin
Inheritance
CurrentPlugin
Inherited Members

Properties

UserData

Returns the user data object that was passed in when a HostFunction was registered.

[Obsolete("Use GetUserData<T> instead.")]
public nint UserData { get; }

Property Value

nint

Methods

AllocateBlock(long)

Allocate a memory block in the currently running plugin.

public long AllocateBlock(long length)

Parameters

length long

Returns

long

BlockLength(long)

Get the length of an allocated block. NOTE: this should only be called from host functions.

public long BlockLength(long offset)

Parameters

offset long

Returns

long

FreeBlock(long)

Frees a block of memory belonging to the current plugin.

public void FreeBlock(long offset)

Parameters

offset long

GetCallHostContext<T>()

Get the current plugin call's associated host context data. Returns null if call was made without host context.

public T? GetCallHostContext<T>()

Returns

T

Type Parameters

T

GetMemory()

Returns a offset to the memory of the currently running plugin. NOTE: this should only be called from host functions.

public long GetMemory()

Returns

long

GetUserData<T>()

Returns the user data object that was passed in when a HostFunction was registered.

public T? GetUserData<T>()

Returns

T

Type Parameters

T

ReadBytes(long)

Returns a span of bytes for a given block.

public Span<byte> ReadBytes(long offset)

Parameters

offset long

Returns

Span<byte>

ReadString(long)

Reads a string from a memory block using UTF8.

public string ReadString(long offset)

Parameters

offset long

Returns

string

ReadString(long, Encoding)

Reads a string form a memory block.

public string ReadString(long offset, Encoding encoding)

Parameters

offset long
encoding Encoding

Returns

string

WriteBytes(long, Span<byte>)

Writes a byte array into a block of memory.

public void WriteBytes(long offset, Span<byte> bytes)

Parameters

offset long
bytes Span<byte>

WriteBytes(Span<byte>)

Writes a byte array into a newly allocated block of memory.

public long WriteBytes(Span<byte> bytes)

Parameters

bytes Span<byte>

Returns

long

Returns the offset of the allocated block

WriteString(string)

Writes a string into the current plugin memory using UTF-8 encoding and returns the offset of the block.

public long WriteString(string value)

Parameters

value string

Returns

long

WriteString(string, Encoding)

Writes a string into the current plugin memory and returns the offset of the block.

public long WriteString(string value, Encoding encoding)

Parameters

value string
encoding Encoding

Returns

long