lua-users home
lua-l archive

[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

  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).


[1]	Gemini server:
	Gopher server:

	I also have a 6809 assembler in Lua that's currently unpublished.

[2]	Example: