Skip to main content

Dictionary

Description:

  A record type for storing pairs of string keys and various values.

Class Object: Dictionary Class.

Inherits from: Object.

count

Type: Readonly Field.

Description:

  The number of items in the dictionary.

Signature:

const count: integer

keys

Type: Readonly Field.

Description:

  The keys of the items in the dictionary.

Signature:

const keys: {string}

get

Type: Function.

Description:

  A method for accessing items in the dictionary.

Signature:

get: function(self: Dictionary, key: string): Item

Parameters:

ParameterTypeDescription
keystringThe key of the item to retrieve.

Returns:

Return TypeDescription
Item or nilThe Item with the given key, or nil if it does not exist.

set

Type: Function.

Description:

  A method for setting items in the dictionary.

Signature:

set: function(self: Dictionary, key: string, item: Item)

Parameters:

ParameterTypeDescription
keystringThe key of the item to set.
itemItemThe Item to set for the given key, set to nil to delete this key-value pair.

each

Type: Function.

Description:

  A function that iterates over each item in the dictionary and calls a given function with the item and its key.

Signature:

each: function(self: Dictionary, func: function(Item, string): boolean): boolean

Parameters:

ParameterTypeDescription
funcfunctionThe function to call for each item in the dictionary.This function should take an Item and a string as arguments and return a boolean. Returns true to stop iteration, false to continue.

Returns:

Return TypeDescription
booleanReturns false if the iteration completed successfully, true otherwise.

clear

Type: Function.

Description:

  A function that removes all the items from the dictionary.

Signature:

clear: function(self: Dictionary)

__index

Type: Metamethod.

Description:

  A metamethod that allows accessing items in the dictionary using the index notation, e.g. "dict['key']" or "dict.key".

Signature:

metamethod __index: function(self: Dictionary, key: string): Item

Parameters:

ParameterTypeDescription
keystringThe key of the item to retrieve.

Returns:

Return TypeDescription
Item or nilThe Item with the given key, or nil if it does not exist.

__newindex

Type: Metamethod.

Description:

  A metamethod that allows setting items in the dictionary using the index notation, e.g. "dict['key'] = value" or "dict.key = value".

Signature:

metamethod __newindex: function(self: Dictionary, key: string, item: Item)

Parameters:

ParameterTypeDescription
keystringThe key of the item to set.
itemItemThe Item to set for the given key, set to nil to delete this key-value pair.