Class Dictionary
Dictionary metatype, wrapper for godot_dictionary.
Construct using the idiom Dictionary(from), which calls __new.
Methods
| Dictionary:clear () | Clear the Dictionary, removing all key/value pairs. |
| Dictionary:duplicate ([deep=false]) | Creates a copy of the dictionary, and returns it. |
| Dictionary:empty () | Returns true if the Dictionary is empty. |
| Dictionary:erase (key) | Erase a dictionary key/value pair by key. |
| Dictionary:get (key[, default]) | Returns the current value for the specified key in the Dictionary. |
| Dictionary:has (key) | Returns true if the Dictionary has a given key. |
| Dictionary:has_all (...) | Returns true if the dictionary has all the given keys. |
| Dictionary:hash () | Returns a hashed integer value representing the Dictionary contents. |
| Dictionary:keys () | Returns the list of keys in the Dictionary. |
| Dictionary:merge (dictionary[, overwrite=false]) | Adds elements from dictionary to this Dictionary. |
| Dictionary:next (key) | Returns the next key/value pair Dictionary's, similar to Lua's next. |
| Dictionary:set (key, value) | Set a new value for the specified key in the Dictionary. |
| Dictionary:size () | Returns the number of keys in the Dictionary. |
| Dictionary:to_json () | Returns a String with JSON representation of the Dictionary's contents. |
| Dictionary:values () | Returns the list of values in the Dictionary. |
Metamethods
| Dictionary:__concat (a, b) | Concatenates values. |
| Dictionary:__len () | Alias for size. |
| Dictionary:__new ([value]) | Dictionary constructor, called by the idiom Dictionary(value). |
| Dictionary:__newindex (key, value) | Set a value to Dictionary. |
| Dictionary:__pairs () | Returns the next iterator and self, called by the idiom pairs(dictionary). |
| Dictionary:__tostring () | Returns a Lua string representation of this Dictionary. |
Methods
- Dictionary:clear ()
- Clear the Dictionary, removing all key/value pairs.
- Dictionary:duplicate ([deep=false])
-
Creates a copy of the dictionary, and returns it.
The
deepparameter causes inner Dictionaries and Arrays to be copied recursively, but does not apply to Objects.Parameters:
- deep (default false)
Returns:
- Dictionary:empty ()
-
Returns
trueif the Dictionary is empty.Returns:
-
bool
- Dictionary:erase (key)
-
Erase a dictionary key/value pair by key.
Returns
trueif the given key was present in the Dictionary,falseotherwise. Does not erase elements while iterating over the dictionary.Parameters:
- key Key, boxed with Variant.__new
Returns:
-
bool
- Dictionary:get (key[, default])
-
Returns the current value for the specified
keyin the Dictionary. If the key does not exist, the method returns the value of the optionaldefaultargument, ornilif it is omitted.Parameters:
- key
- default Default value to be returned if key doesn't exist in Dictionary (optional)
Returns:
-
Unboxed value or
defaultor nil - Dictionary:has (key)
-
Returns
trueif the Dictionary has a given key.Parameters:
- key
Returns:
-
bool
- Dictionary:has_all (...)
-
Returns
trueif the dictionary has all the given keys.Parameters:
- ... If only a table or Array value is passed, its values are used as search keys. Otherwise, all passed arguments will be used as search keys.
Returns:
-
bool
- Dictionary:hash ()
-
Returns a hashed integer value representing the Dictionary contents.
This can be used to compare Dictionaries by value.
Note: Dictionaries with the same keys/values but in a different order will have a different hash.
Returns:
-
int
- Dictionary:keys ()
-
Returns the list of keys in the Dictionary.
Returns:
- Dictionary:merge (dictionary[, overwrite=false])
-
Adds elements from
dictionaryto this Dictionary. By default, duplicate keys will not be copied over, unlessoverwriteistrue.Parameters:
- dictionary Dictionary
- overwrite (default false)
- Dictionary:next (key)
-
Returns the next key/value pair Dictionary's, similar to Lua's next.
This is used to iterate over Dictionaries in __pairs.
Parameters:
- key
If
nil, returns the first key/value pair. Otherwise, returns the next key/value pair.
Returns:
- Key
- Value
Or
-
nil
If there are no more keys
See also:
Usage:
local key, value = nil -- First key being
nil, the iteration begins while true do key, value = dict:next(key) if key == nil then break end -- do something end - key
If
- Dictionary:set (key, value)
-
Set a new value for the specified
keyin the Dictionary.Parameters:
- key
- value
- Dictionary:size ()
-
Returns the number of keys in the Dictionary.
Returns:
-
int
- Dictionary:to_json ()
-
Returns a String with JSON representation of the Dictionary's contents.
Returns:
- Dictionary:values ()
-
Returns the list of values in the Dictionary.
Returns:
Metamethods
- Dictionary:__concat (a, b)
-
Concatenates values.
Parameters:
Returns:
- Dictionary:__len ()
-
Alias for size.
Returns:
-
int
See also:
- Dictionary:__new ([value])
-
Dictionary constructor, called by the idiom
Dictionary(value).Parameters:
- value If passed, the key/value pairs will be iterated with pairs and inserted into the new Dictionary using set. Notice that both tables and userdata/cdata with a __pairs metamethod are valid, including another Dictionary. (optional)
Returns:
- Dictionary:__newindex (key, value)
-
Set a value to Dictionary.
If
valueisnil, thekeywill be erased, similarly to Lua tables. To insert a Nil Variant into Dictionary, use set instead.Parameters:
- key
- value
- Dictionary:__pairs ()
-
Returns the next iterator and
self, called by the idiompairs(dictionary).Returns:
- function
- Dictionary self
Usage:
for k, v in pairs(dictionary) do -- do something end
- Dictionary:__tostring ()
-
Returns a Lua string representation of this Dictionary.
Returns: