Lakshmi is a source generator for c# to make working with extism pdk more the idiomatic c# way
- Install the nuget package with
dotnet add package Lakshmi
- Use it
To work with Lakshmi you have to reference the dotnet extism pdk. Using extism forces you to write a more native like c#. Lashmi provides a source generator to use higher level types.
- Importand: Every class that has exporting/importing functions must be annotated with the
JsonContext
-Attribute and a custom JsonContext must be created see. Later versions will generate the coresponding jsontype info for you
record MyPoint(int x, int y);
class Test {
[Import("host", Entry="add")]
public partial int Add(int a, int b);
[Import("host", Entry="getPoint")]
public partial MyPoint GetPoint();
}
record ExtensionInfo(string author, string[] allowed_hosts);
class Test {
[Export("register")]
public static ExtensionInfo Register() {
return new ExtensionInfo("furesoft", []);
}
}
Under the Hood Lakshma uses a source generator that generates all the necessary temproary classes and builds a type shape, see PolyType, to make sure the deserialization works for aot. Imported/exported methods are wrapped in special generated methods.