Symbol
Symbols are userdata
represented by a name. Global symbols are created or obtained through Symbol.get()
while Nonglobal symbols are created through Symbol.new()
. Global and nonglobal symbols will not return the same if compared even if they have the same name.
new
Creates a symbol for a given string.
local None = Symbol.new("None")
Example
print(Symbol.new("None") == Symbol.new("None"))
local None = Symbol.new("None")
print(None == None)
false
true
get
Creates a symbol for a given string or returns the symbol for that string if one already exists.
local None = Symbol.get("None")
Example
print(Symbol.get("None") == Symbol.get("None"))
print(Symbol.get("None") == Symbol.new("None"))
true
false