Tips for golfing in Lua
load
load
is useful in many cases:
-- replace a repeated code segment:
load(("…"):gsub("…","…"))()
-- split a string:
s="1,2,3,4,5,6,7,8,9"
load("a={"..s.."}")()
Other tips
- If you need a function multiple times, assign it to a shorter variable
- Use
("").…
instead of string.…
- Strings delimited by
[[
and ]]
can contain unescaped newlines
- Try to replace
if
with and
/or