Lua 代码
Lua 以编译为 WebAssembly 的 Lua 5.4 运行。它是七种语言中最轻量的一种: 非常适合做一次简短的转换。
| 符号 | 作用 |
|---|---|
input | 从输入端口收到的值 |
vars | 运行变量的一个表 |
print(...) | 写入执行日志(多个参数以制表符连接) |
return | 返回的值会从 result 端口发出 |
local commandes = input.commandeslocal total, nombre = 0, 0
for _, commande in ipairs(commandes) do if commande.statut == "payee" then total = total + commande.montant nombre = nombre + 1 endend
print(string.format("%d commandes payées, total %.2f €", nombre, total))
return { nombre = nombre, total = total }需要知道的事
Section titled “需要知道的事”- Lua 的表是从 1 开始索引的:
input[1]是收到的列表中的第一个元素。 - 键为连续数字的表会输出为 JSON 数组;键为文本的表会输出为对象。
- 标准库可用:
string、table、math、os。
packages 字段接受纯 Lua 源码形式的 LuaRocks 模块。它们会在首次执行时被解析,
之后便离线注入。