Mico
Mico

Reputation: 413

Lua function return

I was wondering if there is any significant difference between

function foo()
  do something
  return bar()
end

and

function foo()
  do something
  bar()
end

Upvotes: 1

Views: 140

Answers (1)

Etan Reisner
Etan Reisner

Reputation: 81052

Two main differences.

The first returns the values returned from bar to the caller of foo. The second ignores them entirely.

The first also gets treated as a tail-call and as such can get eliminated to save a stack frame (prevents recursion from blowing up your stack) whereas the second does not.

Upvotes: 4

Related Questions