https://github.com/nimaoth/nimwasmtime
Nim wrapper for wasmtime
https://github.com/nimaoth/nimwasmtime
Last synced: 12 months ago
JSON representation
Nim wrapper for wasmtime
- Host: GitHub
- URL: https://github.com/nimaoth/nimwasmtime
- Owner: Nimaoth
- License: mit
- Created: 2024-07-13T23:01:51.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-06-23T19:17:00.000Z (12 months ago)
- Last Synced: 2025-06-23T20:25:44.763Z (12 months ago)
- Language: Nim
- Size: 834 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nimwasmtime
Nim wrapper for wasmtime
This wrapper is auto-generated with [Futhark](https://github.com/PMunch/futhark), but also tries to add some nicer wrappers
around some functions.
## Installation
Add this to your nimble file:
```nim
requires "https://github.com/Nimaoth/nimwasmtime >= 0.1.9"
```
## Usage
See [here](tests/test2.nim) for more examples.
```nim
import std/[strformat, options]
import wasmtime
proc main() =
let config = newConfig()
let engine = newEngine(config)
let linker = engine.newLinker()
defer: linker.delete()
let store = engine.newStore(nil, nil)
defer: store.delete()
let context = store.context()
let wasiConfig = newWasiConfig()
wasiConfig.inheritStdin()
wasiConfig.inheritStderr()
wasiConfig.inheritStdout()
context.setWasi(wasiConfig).toResult(void).okOr(err):
echo "Failed to setup wasi: ", err.msg
return
let wasmBytes = readFile("tests/wasm/testm.wasm")
let module = engine.newModule(wasmBytes).okOr(err):
echo "Failed to load wasm module: ", err.msg
return
linker.defineWasi().okOr(err):
echo "Failed to create linker: ", err.msg
return
var trap: ptr WasmTrapT = nil
let instance = linker.instantiate(context, module, trap.addr).okOr(err):
echo "Failed to instantiate wasm module: ", err.msg
return
trap.okOr(err):
echo "[trap] Failed to instantiate wasm module: ", err.msg
return
let mainExport = instance.getExport(context, "hello")
mainExport.get.of_field.func_field.addr.call(context, [], [], trap.addr).toResult(void).okOr(err):
echo "Failed to call hello: ", err.msg
return
main()
```