David
David

Reputation: 3

Lua - What is the most optimized method of a Lua function?

I searched before I ask my question. I have two method to make a loop. And I wonder what the two is the more optimized. And may be you can find better. The goal is to loop every 1 seconds. This already works.

Thank you to time to explain. Which one is the best. Before proposing a third option.

Edit:

Legend: 0 in timer.Create = infinit loop. 1 in timer.Create = launch the function, 1 per second.

The contents of the function is simplified by something that does not seem to be helpful to the base. But what interests me is the basic method.

Upvotes: 0

Views: 414

Answers (1)

Etan Reisner
Etan Reisner

Reputation: 81052

Putting the function in a table gains you nothing and forces an extra table lookup.

Adding the extra wrapping (unnamed) function in the timer.Create call is also not a useful thing to do as it just adds an extra function calls overhead to the process.

Using locals is always better than using globals.

Something like the following is likely the best:

local content = 0
local function loop1()
    content = content + 1
end

timer.Create("myloop", 1, 0, loop1)

Upvotes: 2

Related Questions