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
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
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?

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

2 answers

You are accessing this answer with a direct link, so it's being shown above all other answers regardless of its score. You can return to the normal view.

+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!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+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.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »