Tips in golfing using Lua
Lua's not really used much in golfing, so it'd be pretty cool to learn some golfing tricks when making answers using it.
What golfing tips are there for Lua?
2 answers
Remove print
's parentheses when it's a single string
print
strangely works without parentheses, however, it only applies to single strings. In other words, it can't do the same for other variables or string concatenation inside the function.
For example:
print("Hello, World!")
Works, but can be shortened to:
print"Hello, World!"
Saving 2 bytes for all cases.
These don't work:
i=10
print i
name="Mark"
print"Hello, "..name.."."
You'll need to encase them in parentheses if so.
0 comment threads
Convenient whitespace removal
Here are instances where you can remove whitespace:
Strings
If you assigned or printed a string, then the next supposed line of code can lean on the right double-quote:
--[[
name = "Mark"
print(name)
]]
name="Mark"print(name)
Commented code works the same.
Functions
Similar to strings, you can let the next line of code lean onto the right parentheses:
name="Mark"
print("Hello!")print(name)print("Have fun!")
0 comment threads