跳到內容

Lua 程式碼

Lua 以編譯成 WebAssembly 的 Lua 5.4 執行。它是七種語言中最輕巧的一個:非常 適合用來做一次簡短的轉換。

符號用途
input從輸入連接埠收到的值
vars一個裝著執行變數的表
print(...)寫入執行記錄(各個引數之間以定位字元相連)
return回傳的值會走 result 連接埠送出
local commandes = input.commandes
local total, nombre = 0, 0
for _, commande in ipairs(commandes) do
if commande.statut == "payee" then
total = total + commande.montant
nombre = nombre + 1
end
end
print(string.format("%d commandes payées, total %.2f €", nombre, total))
return { nombre = nombre, total = total }
  • Lua 的表是從 1 開始索引的:input[1] 就是收到的清單裡的第一個項目。
  • 索引鍵為連續數字的表會輸出成 JSON 陣列;索引鍵為文字的表則輸出成物件。
  • 標準函式庫都可以使用:stringtablemathos

packages 欄位接受以純 Lua 原始碼提供的 LuaRocks 模組。它們會在第一次執行時 解析,之後便以離線方式注入。