How to use Extism .NET SDK with PowerShell (2) #127
StSchnell
started this conversation in
Show and tell
Replies: 1 comment
-
@StSchnell thank you very much for this detailed tutorial! This is very helpful for windows admins and people who use PowerShell daily |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The first example shows how to use the standard count_vowels. This was important, because simply to show that PowerShell can also be used with the Extism .NET SDK. PowerShell is often used to automate repetitive tasks and is frequently used in companies. A combined application of PowerShell and WebAssembly can certainly be used very profitably in some places. That's why I took a look at the parameter passing options. We discussed this in another context briefly in Discord and it was suggested to use JSON.
To build a WASM file I use the Extism C-PDK and I decided to use JSMN (Jasmine) a minimalistic JSON parser in C. As a realization example, I chose a simple addition of two numbers. The focus of this post is on the data transfer between PowerShell and WebAssembly and vice versa. The following example gives us a basis.
We start with the file addition.h. The logic is not complex, so the code is easy to understand. The function _addition initialize the JSON parser and parses the input, which is split into tokens. In the following loop we get the key and the value of the JSON property and assign it to our variables. We add them and return the result as a string in JSON.
Now the file addition.c. There is not much to say about this, it is standard. Exceptions are the additional header files and the call of the addition function.
Now the file addition.ps1. For the most part it is identically to the code presented in the first example. Only the definition of the input parameters is now JSON and so is the return.
We can conclude (with greater certainty) that it is possible to use the Extism .NET SDK with PowerShell. It was important for me to show here that data can be passed on in JSON format. This means that a lot is possible.
Beta Was this translation helpful? Give feedback.
All reactions