https://github.com/furesoft/lakshmi
Lakshmi is a source generator for c# to make working with extism pdk more idiomatic c#
https://github.com/furesoft/lakshmi
csharp dotnet extism generator wasm
Last synced: 6 months ago
JSON representation
Lakshmi is a source generator for c# to make working with extism pdk more idiomatic c#
- Host: GitHub
- URL: https://github.com/furesoft/lakshmi
- Owner: furesoft
- License: gpl-3.0
- Created: 2025-03-26T14:57:30.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-03-31T16:43:05.000Z (6 months ago)
- Last Synced: 2025-04-05T06:28:07.325Z (6 months ago)
- Topics: csharp, dotnet, extism, generator, wasm
- Language: C#
- Homepage:
- Size: 76.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Lakshmi
Lakshmi is a source generator for c# to make working with extism pdk more the idiomatic c# way[](https://www.codefactor.io/repository/github/furesoft/lakshmi)


[](https://www.gnu.org/licenses/gpl-3.0)

# 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](https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/source-generation). Later versions will generate the coresponding jsontype info for you## Importing functions
```csharp
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
```csharp
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](https://github.com/eiriktsarpalis/PolyType), to make sure the deserialization works for aot. Imported/exported methods are wrapped in special generated methods.