콘텐츠로 이동

Lua 코드

Lua는 WebAssembly로 컴파일한 Lua 5.4로 실행됩니다. 7 개 언어 가운데 가장 가벼우므로 짧은 변환 작업에 알맞습니다.

심볼역할
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 배열로, 문자열 키를 가진 테이블은 객체로 나옵니다.
  • 표준 라이브러리를 사용할 수 있습니다. string, table, math, os 입니다.

packages 필드는 순수 Lua 소스로 된 LuaRocks 모듈을 받아들입니다. 첫 실행 때 해석한 뒤, 이후에는 오프라인으로 주입합니다.