Expand description
The Weirdnet plugin C ABI, version 2. Shared verbatim by hosts and plugins.
Version 2 has the same layout and calling convention as version 1 of the SDK this one descends from; it differs in its symbol names and version number, so a host knows which SDK a library was built against and never mistakes one for the other.
A plugin is a shared library (.so, .dylib, .dll) exporting three symbols:
| symbol | signature | meaning |
|---|---|---|
weirdnet_plugin_abi | extern "C" fn() -> u32 | the ABI version it was built for (ABI_VERSION) |
weirdnet_plugin_info | extern "C" fn() -> WnStr | static UTF-8 JSON: {"sdk": "0.1.0", "lang": "rust"} (and "kind" from plugin!(run, kind = "…")) |
weirdnet_plugin_run | unsafe extern "C" fn(*const WnHost) -> i32 | run once; RUN_OK or an error code |
Everything else goes through the host table WnHost: call(ctx, method, request, out)
takes a method name and a JSON request and fills out with a JSON reply that the plugin
returns with free. Memory never crosses allocators: the host frees what it allocates,
and the plugin only lends (WnStr) what it owns.
Compatibility: the layout of these types and the three symbols never change within an
ABI version. New host methods may be added at any time (methods lists them); a plugin
asking for a method the host does not know gets an error, never a crash. A host refuses
plugins whose weirdnet_plugin_abi is not one it supports.
Structs§
- WnBuf
- Bytes owned by the host; give them back with
WnHost::free. - WnHost
- What the host gives a plugin for one run.
- WnStr
- Borrowed UTF-8 bytes.
Constants§
- ABI_
VERSION - The ABI version this file describes.
- CALL_
ERROR callfailed andoutholds the error message (UTF-8, not JSON).- CALL_OK
callsucceeded andoutholds the JSON reply.- RUN_
ERROR - The run failed with an error (sent to the host with the
errormethod). - RUN_OK
weirdnet_plugin_runfinished; the result (or error) was handed to the host.- RUN_
PANIC - The plugin panicked (the panic was caught; its message was sent with
error). - SYM_ABI
- Exported symbol names (NUL-terminated for
dlsym). - SYM_
INFO - SYM_RUN
Type Aliases§
- Host
Call - Calls a host method:
methodname,requestJSON; fillsout; returnsCALL_OKorCALL_ERROR. - Host
Free - Frees a buffer the host filled.
- Plugin
Abi - Plugin
Info - Plugin
Run