Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/extism/assemblyscript-pdk
Extism Plug-in Development Kit (PDK) for AssemblyScript
https://github.com/extism/assemblyscript-pdk
Last synced: 2 months ago
JSON representation
Extism Plug-in Development Kit (PDK) for AssemblyScript
- Host: GitHub
- URL: https://github.com/extism/assemblyscript-pdk
- Owner: extism
- License: bsd-3-clause
- Created: 2022-08-30T00:44:15.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-23T17:42:53.000Z (5 months ago)
- Last Synced: 2024-09-23T20:06:46.564Z (4 months ago)
- Language: TypeScript
- Size: 38.1 KB
- Stars: 7
- Watchers: 3
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
- awesome-wasm-runtimes - `AssemblyScript`
README
# Extism AssemblyScript PDK
### Installation
```sh
npm install @extism/[email protected] --save
```### Compiling to WebAssembly
Use the AssemblyScript compiler, `asc`:
```sh
npx asc example.ts --outFile example.wasm --use abort=example/myAbort
```### Example Usage
```typescript title=example.ts
import { Host, Var, Config } from '@extism/as-pdk';function myAbort(
message: string | null,
fileName: string | null,
lineNumber: u32,
columnNumber: u32
): void { }export function count_vowels(): i32 {
let str = Host.inputString();
var count = 0;
for (var i = 0; i < str.length; i++) {
let x: string = str[i];
if (x == 'a' || x == 'A' ||
x == 'e' || x == 'E' ||
x == 'i' || x == 'I' ||
x == 'o' || x == 'O' ||
x == 'u' || x == 'U') {
count += 1;
}
}// Additional plug-in APIs:
// persistent variables (scoped to individual plugin)
var a = Uint8Array.wrap(String.UTF8.encode("this is var a"))
Var.set('a', a);let data = Var.get('a');
let var_a = (data == null) ? "null" : String.UTF8.decode(data.buffer);// config, provided by the host
const thing = Config.get("thing");// write data back to host for use in program
var out = '{"count": ' + count.toString() + ', "config": "' + (thing == null ? "null" : thing) + '", "a": "' + var_a + '"}';
Host.outputString(out);
Var.remove('a');return 0;
}
```