lua-users home
lua-l archive

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

On Jun 22, 2022, at 11:08 AM, Ryan Starrett <> wrote:

On Wed, Jun 22, 2022 at 4:22 AM Egor Skriptunoff <> wrote:
A question about Lua coding style.
Is it a good or bad idea to distinguish global from local variables by its uppercase / lowercase initial letter?
Var=0 -- global
var=0 -- local or upvalue

Neither I'd wager. Seems like personal preference, and from that I'll sprout a case that an alternative naming style for globals appears ideal. Of course, you could also vouch for no naming changes and explicitly use _G to look up the global. Some may call this ugly, but it's about as explicit as you'll get haha.

But _G.x isnt quite the same as x by itself, since Lua will change x into _ENV.x (where _ENV usually but not always contains a ref to _G)