Code · 1 file

Sample Lua File

Lua is a small embeddable scripting language used in games, Neovim and Redis. The Lua sample is a small program — a customer record, a VIP check and a formatted total — that is the same in every language we offer, so you can compare them side by side.

Lua · 470 B

Sample Lua file

An idiomatic Lua example: a customer record type, a VIP check, a total and a formatted loop — the same program in every language we offer.

CC0 · free for any use · Verified by an independent tool · Report a problem

sample.lua — first linesLua
-- Sample Lua script — samplefiles.com
local customers = {
  { id = 1, name = "Ada", balance = 12500 },
  { id = 2, name = "Grace", balance = 830.5 },
  { id = 3, name = "Linus", balance = 10000 },
}

local function is_vip(c) return c.balance >= 10000 end

local total = 0
for _, c in ipairs(customers) do
  print(string.format("%-6s %10.2f %s", c.name, c.balance, is_vip(c) and "VIP" or ""))
  total = total + c.balance
end
print(string.format("Total: %.2f", total))

File details

Size
470 B (470 bytes)
MIME type
text/x-lua
SHA-256
4f37330558d9dded1493a273a94e6321aa98c1a2dc79c36e8ba588a910fb385b
MD5
75354ec59b21b0460a7618f7f1584be3

Download from the command line

curl -L -o sample.lua https://files.samplefiles.com/code/lua/sample.lua

Or check the download in your browser with the checksum calculator.