Ex:
__Index (or something to that nature)
local t = {}
setmetatable( t, {
__newindex = function( t, k, v )
error('cant edit table', 2)
end
})
try this code out and try to set a new value to t ;)/>I'm most programming languages the convention for private variables or properties of objects is a single `_` not double. The double `__` in all languages that I have seen it in relates to metamethods. For example Python also has metamethods defined like so `__init__`.In general "__" are meant to indicate 'private' variables and are mainly a coding style/practice
The use of two underscores (`__') in identifiers is reserved for the compiler's internal use according to the ANSI-C standard.
Underscores (`_') are often used in names of library functions (such as "_main" and "_exit"). In order to avoid collisions, do not begin an identifier with an underscore.
The use of two underscores (`__') in identifiers is reserved for the compiler's internal use according to the ANSI-C standard.
Underscores (`_') are often used in names of library functions (such as "_main" and "_exit"). In order to avoid collisions, do not begin an identifier with an underscore.
From http://www.doc.ic.ac.uk/lab/cplus/c++.rules/chap5.html
Most languages I know use it as a private 'not meant to be accessed' variable/function, however you are probably right for languages such as lua and python.
The use of two underscores (`__') in identifiers is reserved for the compiler's internal use according to the ANSI-C standard.
local function myFunction(_underscore, _var)
--#No collisions here!
end
local regularVar = 5
The use of two underscores (`__') in identifiers is reserved for the compiler's internal use according to the ANSI-C standard.
Underscores (`_') are often used in names of library functions (such as "_main" and "_exit"). In order to avoid collisions, do not begin an identifier with an underscore.
I always use a single underscore for variables that are taken by functions. e.glocal function myFunction(_underscore, _var) --#No collisions here! end local regularVar = 5
I always use a single underscore for variables that are taken by functions. e.glocal function myFunction(_underscore, _var) --#No collisions here! end local regularVar = 5
You may as well drop them. The only reason to have "_var" is if you'll be accessing "var" in the environment. As in, you're using both var and _var in the function, in which case _var should probably be called something else entirely. And even if they're both called var, you can explicitly refer to the one in the environment by going through the environment table.