class
TableA lua table value.
Contents
Table is basically a std::map
. Aditionally table is aliasable (i.e. it acts like a std::sharded_ptr
). That means two variables (or two Table
Value
s) can refer to the same actual table.
Support equality operators.
Is hashable.
Public types
- class const_iterator
- Const iterator through a Table.
- class iterator
- Iterator through a Table.
Public static variables
- static static const std::string_view TYPE constexpr
- The type of this value as a string.
Constructors, destructors, conversion operators
- Table()
- Creates an empty table in the GLOBAL_
ALLOCATOR. - Table(MemoryAllocator* allocator)
- Creates an empty table in the given allocator.
-
Table(std::unordered_map<Value, Value>,
MemoryAllocator* allocator = &GLOBAL_
ALLOCATOR) - Creates and fills a table in the given allocator.
-
Table(std::initializer_list<std::pair<const Value, Value>> values,
MemoryAllocator* allocator = &GLOBAL_
ALLOCATOR) - Creates and fills a table in the given allocator.
- Table(TableImpl* impl, MemoryAllocator* allocator)
- Construct a table directly from a pointer to it's impl.
- Table(const Table& other, MemoryAllocator* allocator)
- Copy a table to a different allocator.
- Table(const Table& other)
- Copy constructor.
- Table(Table&& other) noexcept
- Move constructor.
- operator bool() const explicit
- Convert the value to a bool (always
true
).
Public functions
- auto operator=(const Table& other) -> Table & -> auto
- Copy assignment operator.
- auto operator=(Table&& other) noexcept -> Table & -> auto
- Move assignment operator.
- auto allocator() const -> MemoryAllocator * -> auto
- Returns the used allocator.
- auto border() const -> int -> auto
- The result of the lua length operator
#
. - auto contains_function() const -> bool -> auto
- auto get(const Value& key) const -> Value -> auto
- Try to get the value with the given key.
- auto has(const Value& key) const -> bool -> auto
- Check if the table has a value for the given key.
- void set(const Value& key, Value value)
- Sets the key to value.
- void set(Value&& key, Value value)
- Sets the key to value.
- void set_all(const Table& other)
- auto size() const -> size_t -> auto
- The number of values in the table.
- auto begin() -> iterator -> auto
- Returns an iterator to the beginning.
- auto begin() const -> const_iterator -> auto
- Returns an iterator to the beginning.
- auto cbegin() const -> const_iterator -> auto
- Returns an iterator to the beginning.
- auto end() -> iterator -> auto
- Returns an iterator to the end.
- auto end() const -> const_iterator -> auto
- Returns an iterator to the end.
- auto cend() const -> const_iterator -> auto
- Returns an iterator to the end.
- auto to_literal() const -> std::string -> auto
- Converts the value to it's literal representation.
- auto next(const Value& key) const -> Vallist -> auto
- The next index of the table and its associated value after index.
- void remove(const Value& key)
- auto get_metatable() const -> std::optional< Table > -> auto
- Returns the current metatable of this table.
- void set_metatable(std::optional<Table> metatable)
- Sets the metatable of this table.
- auto get_metamethod(const std::string& metamethod) const -> Value -> auto
- Returns the metamethod or
Nil
if it or the metatable is not present. - auto operator[](const Value&) -> Value & -> auto
- Access a value by key.
- auto operator[](const Value&) const -> const Value & -> auto
- Access a value by key.
Friends
- void swap(Table& self, Table& other)
- Swap function.
- auto operator==(const Table&, const Table&) noexcept -> bool -> auto
- Equality comparions.
- auto operator!=(const Table&, const Table&) noexcept -> bool -> auto
- Unequality comparions.
Function documentation
minilua:: Table:: Table(TableImpl* impl,
MemoryAllocator* allocator)
Construct a table directly from a pointer to it's impl.
minilua:: Table:: Table(const Table& other,
MemoryAllocator* allocator)
Copy a table to a different allocator.
This will make a deep copy meaning all nested tables will also be copied to the allocator.
auto minilua:: Table:: border() const -> int
The result of the lua length operator #
.
Satisfies: (border == 0 or t[border] ~= nil) and t[border + 1] == nil
auto minilua:: Table:: contains_function() const -> bool
Checks if the table contains a Function.
auto minilua:: Table:: next(const Value& key) const -> Vallist
The next index of the table and its associated value after index.
Parameters | |
---|---|
key | The index you want to get the next element. |
Returns | An empty Vallist when called with the last index or on an empty table. Else it returns the next index and its associated value. |
If there is no value at the index an exception is thrown.
void minilua:: Table:: remove(const Value& key)
Removes the element of the Table including its key.
This method should just be used as a helper for table.remove to remove the key as well as the value
auto minilua:: Table:: get_metamethod(const std::string& metamethod) const -> Value
Returns the metamethod or Nil
if it or the metatable is not present.
This will not check if the value is actually a function.
auto operator==(const Table&, const Table&) noexcept -> bool
Equality comparions.
Does not compare the content of two tables, only if the table actually represent the same table.
auto operator!=(const Table&, const Table&) noexcept -> bool
Unequality comparions.
Does not compare the content of two tables, only if the table actually represent the same table.