Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs

Dashboard
Notifications
Mark all as read
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?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

2 answers

+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?
You might want to add some details to your flag.

0 comment threads

+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?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »

This community is part of the Codidact network. We have other communities too — take a look!

You can also join us in chat!

Want to advertise this community? Use our templates!