Function that does nothing in Lua

Question:

I’ve recently started learning Lua. The only other programming language I have some experience in is Python. In Python there is the “pass” function that does nothing. I was wondering what the equivalent (if any) of this would be in Lua.

Asked By: InTheory

||

Answers:

In Python, pass is an important placeholder for incomplete code. It must exist because Python doesn’t allow empty code blocks. Stuff like if statements, loops etc. require a body, so you place a pass there when you want to leave the implementation for later.

def myfunction(a, b, c):
    pass # im doing this later

In Lua, however, this is not necessary. It is perfectly fine to end an if or a function without including any body, so there is no need for a pass in Lua.

function myfunction(a, b, c)
    -- im doing this later
end
Answered By: Havenard

Leave your conditional empty by doing this

if <condition> then end

Answered By: Andy
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.