Skip to content

Lakshmi is a source generator for c# to make working with extism pdk more idiomatic c#

License

Notifications You must be signed in to change notification settings

furesoft/Lakshmi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lakshmi

Lakshmi is a source generator for c# to make working with extism pdk more the idiomatic c# way

CodeFactor NuGet Version NuGet Downloads License: GPL v3 Discord Libraries.io SourceRank

Installation

  1. Install the nuget package with dotnet add package Lakshmi
  2. Use it

Usage

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

Importing functions

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();
}

Exporting functions

record ExtensionInfo(string author, string[] allowed_hosts);

class Test {
  [Export("register")]
  public static ExtensionInfo Register() {
    return new ExtensionInfo("furesoft", []);
  }
}

How does it work?

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.

About

Lakshmi is a source generator for c# to make working with extism pdk more idiomatic c#

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages