Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

内置示例

English

编译器仓库提供四个小型示例包。先安装 pud,再克隆仓库。下表中的命令从仓库根目录开始执行。

包内容命令
todo读取 JSON 与处理错误cd examples/todo 后运行 pud run
wordfreq读取标准输入并用映射统计词频printf 'a b a\n' | pud run examples/wordfreq
plugin实现自定义 WIT world 的导出pud build examples/plugin --target plugin
plugin-host在一个组件中使用多种宿主能力pud build examples/plugin-host --target plugin

todo 在进程工作目录读取 todos.json,会输出 2 of 4 left。wordfreq 输出 a 出现 2 次、b 出现 1 次。两个插件分别在各自包目录中生成 target/plugin/plug.wasm 和 target/plugin/plugin-host.wasm。

需要实际调用插件时,可照着插件入门运行。plugin 示例的 greet 导出需要宿主提供 demo:host/log,而 classify 不会调用该接口。