lua-users home
lua-l archive

Re: Uppercase-initial globals

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


It was thus said that the Great Egor Skriptunoff once stated:
> 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
> https://stackoverflow.com/questions/72710110/uppercase-or-lowercase-for-global-variables
 I don't use globals in Lua. Of the actual Lua apps that I have [1] none
use global variables. I do, however, do put "global" data for the app in
its own table and make it available via require() (usually, require("CONF"))
so I don't have to pass it around everywhere.
 I've also cut down on my use of global variables in C, and when I do have
a global variable, it starts with a 'g', for example, 'g_L' for a global Lua
state. If it's meant to be read-only, I'll prefix it with 'c', for example,
'c_numaflinks' [2]. For static variables outside of a function, I'll prefix
the variable with 'm' (it makes sense for me).
 -spc
[1]	Gemini server: https://github.com/spc476/GLV-1.12556
	Gopher server: https://github.com/spc476/port70
	I also have a 6809 assembler in Lua that's currently unpublished.
[2]	Example: https://github.com/spc476/mod_blog/blob/master/src/globals.h

AltStyle によって変換されたページ (->オリジナル) /