lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hi all,

In other programming languages, I used to declare objects before loops in order not to re-create one at each loop, for instance in Java :
MyObject hello =;
// use and reuse 'hello' here, without the overhead of recreating the object at each loop

In Lua, I often do the same:
local a = ""
for ...
a = ... -- use variable a, change its value, etc. (here variable 'a' is 'non-local' thus with no indexed search)

Would it be better Lua programming (in terms of *speed* optimization) to do directly:
local a = ... -- because here the variable 'a' is local and not 'non-local', thus very quickly resolved (indexed) even if recreated at each loop

Thank you for your thoughts and comments about it!

Personnalisez votre Messenger avec