Q&A

Tips in golfing using Lua

+0
−0

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?

Why does this post require moderator attention?
Why should this post be closed?

+0
−0

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.

Try it online!

These don't work:

i=10
print i


Try it online!

name="Mark"
print"Hello, "..name.."."


Try it online!

You'll need to encase them in parentheses if so.

Why does this post require moderator attention?

+0
−0

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)


Try it online!

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!")


Try it online!

Why does this post require moderator attention?