Files and Streams
First Line
Reading the first line is a common stream operation.
first record
The first logical line is often a title, header, or command before later data.
First Line
first_line.lua
Replay: real traced execution (multi-file project)
local raw = "title|body"
local text = string.gsub(raw, "|", "\n")
local first = string.match(text, "^[^\n]+")
print("raw=" .. raw)
print("first=" .. first)
local raw = "header|detail"
local text = string.gsub(raw, "|", "\n")
local first = string.match(text, "^[^\n]+")
print("raw=" .. raw)
print("first=" .. first)
local raw = "single"
local text = string.gsub(raw, "|", "\n")
local first = string.match(text, "^[^\n]+")
print("raw=" .. raw)
print("first=" .. first)
raw ← title|body, text ← title body, first ← title
1local raw→ title|body = "title|body" --@raw="header|detail", "single"2local text→ title body = string.gsub(rawtitle|body, "|", "\n")3local first→ title = string.match(texttitle body, "^[^\n]+")45print("raw=" .. rawtitle|body)6print("first=" .. firsttitle)outputraw=title|body first=title
raw ← header|detail, text ← header detail, first ← header
1local raw→ header|detail = "header|detail"2local text→ header detail = string.gsub(rawheader|detail, "|", "\n")3local first→ header = string.match(textheader detail, "^[^\n]+")45print("raw=" .. rawheader|detail)6print("first=" .. firstheader)outputraw=header|detail first=header
raw ← single, text ← single, first ← single
1local raw→ single = "single"2local text→ single = string.gsub(rawsingle, "|", "\n")3local first→ single = string.match(textsingle, "^[^\n]+")45print("raw=" .. rawsingle)6print("first=" .. firstsingle)outputraw=single first=single