Lua
1993fragletscriptingimperativescripting.lua
docker run --rm --platform="linux/amd64" 100hellos/lua:latest
MCP + fragletc
MCPstdinargs
This language supports code execution via MCP and the fragletc CLI. Stdin piping and argument passing are both supported.
Install fragletc →Lua is a scripting imperative and scripting language first appearing in 1993.
Hello World
#!/usr/bin/env lua5.4
print("Hello World!")Coding Guide
Language Version
Lua 5.4
Execution Model
- Interpreted, runs directly from source
- Fragment executes inside a
main()function - Interpreter launches once, runs
main(), then exits - Output must be explicit (
print,io.write)
Key Characteristics
- Dynamic typing
- Case-sensitive
- Tables are the primary data structure
- Prefer
localvariables to avoid leaking globals
Fragment Authoring
Write valid Lua statements. Your fragment becomes the main function body. Code runs inside the main function, then the interpreter exits. Define helper functions before using them.
Available Packages
Standard libraries are available:
string- string manipulationtable- table operationsmath- mathematical functionsio- input/output operationsos- operating system interface
Common Patterns
- Print:
print("message") - Local variables:
local message = "Hello" - Tables:
local list = {1, 2, 3} - Functions:
local function greet(name) return string.format("Hi, %s", name) end - Iteration:
for i, value in ipairs(list) do ... end - Table iteration:
for key, value in pairs(table) do ... end
Examples
-- Simple output
print("Hello, World!")
-- Function definition
local function greet(name)
return string.format("Hello, %s!", name)
end
print(greet("Alice"))
-- Table processing
local numbers = {1, 2, 3, 4, 5}
local sum = 0
for i, value in ipairs(numbers) do
sum = sum + value * value
end
print(string.format("Sum of squares: %d", sum))Caveats
- Globals persist only for the single run
- Use
localto avoid polluting the global namespace - External
requirecalls only work if the module exists in the runtime environment
Fraglet Scripts
Echo Args
#!/usr/bin/env -S fragletc --vein=lua
print("Args: " .. table.concat(arg, " "))Stdin Upper
#!/usr/bin/env -S fragletc --vein=lua
for line in io.lines() do
print(string.upper(line))
endTable Process
#!/usr/bin/env -S fragletc --vein=lua
local numbers = {1, 2, 3, 4, 5}
local sum = 0
for i, value in ipairs(numbers) do
sum = sum + value * value
end
print(string.format("Sum of squares: %d", sum))Test
#!/usr/bin/env -S fragletc --vein=lua
print("Hello World!")