Forum Discussion

EnTerr's avatar
EnTerr
Roku Guru
12 years ago

Precedence: local vs global function?

What is the precedence (lookup order) when calling a function?

For example say i have defined function exec() in global scope and then inside another function or method i do:
exec = function(): return "bar": end function
exec()
Which function should be called?

I did a quick tests and seems that global one prevails but this is counter-intuitive. It is customary that binding be resolved to the most local/domestic definition - which in this case is the local assignment of anonymous fn. Doing it the other way risks unpredictable results - say as shown i define and use locally some worker function. All is well while there is no global exec() - but one day somebody adds exec() to a library i use and boom - weird things happen.
No RepliesBe the first to reply