Simple Lua
A Simple C++ Lua Wrapper
Loading...
Searching...
No Matches
SL::Table Struct Reference

Classes

struct  Data
 Represents a value in the table stored in memory with a type. More...
 

Public Types

using Map = std::unordered_map<std::string, Data>
 

Public Member Functions

SL_SYMBOL Table (const Map &map)
 
SL_SYMBOL Table (State L)
 Constructs a table from the current Lua stack.
 
SL_SYMBOL const DatagetRaw (const std::string &name) const
 
template<typename T >
SL_SYMBOL void each (std::function< void(uint32_t, T &)> lambda)
 
template<typename T >
SL_SYMBOL void each (std::function< void(uint32_t, const T &)> lambda) const
 
template<typename T >
SL_SYMBOL void try_get (const std::string &name, std::function< void(T &)> lambda, std::optional< std::function< void()> > if_not=std::nullopt)
 
template<typename T >
SL_SYMBOL void try_get (const std::string &name, std::function< void(const T &)> lambda, std::optional< std::function< void()> > if_not=std::nullopt) const
 
SL_SYMBOL void fromTable (const Table &table)
 Make the entries equivalent to another table.
 
SL_SYMBOL void superimpose (const Table &table)
 Copy the entries from a table into this table.
 
SL_SYMBOL void superimpose (const Map &map)
 Copy the entries from a map into this table.
 
SL_SYMBOL bool hasValue (const std::string &name) const
 
template<typename T >
SL_SYMBOL T & get (const std::string &name)
 Get a reference to a value in the table.
 
template<typename T >
SL_SYMBOL std::vector< T > get () const
 
template<typename T >
SL_SYMBOL const T & get (const std::string &name) const
 Get a constant reference to a value in the table.
 
SL_SYMBOL void * get (const std::string &name) const
 
template<typename T >
SL_SYMBOL void set (const std::string &name, const T &value)
 Set the value associated with a key.
 
SL_SYMBOL void set (const std::string &name, void *value)
 
SL_SYMBOL const Map & getMap () const
 Get the raw mapping of this table.
 
SL_SYMBOL void toStack (State L) const
 Dump all the map information onto the given Lua stack.
 
SL_SYMBOL void fromStack (State L)
 
SL_SYMBOL std::string toString (uint32_t indent=0) const
 

Constructor & Destructor Documentation

◆ Table()

SL_SYMBOL SL::Table::Table ( State L)

Constructs a table from the current Lua stack.

This assumes that there is a table already at index -1 in the Lua stack. Once executed, it pops the table off the stack completely.

Parameters
L

Member Function Documentation

◆ fromTable()

SL_SYMBOL void SL::Table::fromTable ( const Table & table)

Make the entries equivalent to another table.

Parameters
tableTable to get the entries from

◆ get() [1/2]

template<typename T >
SL_SYMBOL T & SL::Table::get ( const std::string & name)

Get a reference to a value in the table.

Template Parameters
TType of the value (with SL:: prefix)
Parameters
nameThe value's key
Returns
T& The reference to the value

◆ get() [2/2]

template<typename T >
SL_SYMBOL const T & SL::Table::get ( const std::string & name) const

Get a constant reference to a value in the table.

Template Parameters
TType of the value (with SL:: prefix)
Parameters
nameThe value's key
Returns
const T& The constant reference to the value

◆ getMap()

SL_SYMBOL const Map & SL::Table::getMap ( ) const

Get the raw mapping of this table.

Returns
const Map& The map in this table

◆ set()

template<typename T >
SL_SYMBOL void SL::Table::set ( const std::string & name,
const T & value )

Set the value associated with a key.

Template Parameters
TThe type of the value (with SL:: prefix)
Parameters
nameThe key
valueThe value

◆ superimpose() [1/2]

SL_SYMBOL void SL::Table::superimpose ( const Map & map)

Copy the entries from a map into this table.

Parameters
mapMap to get the entries from

◆ superimpose() [2/2]

SL_SYMBOL void SL::Table::superimpose ( const Table & table)

Copy the entries from a table into this table.

Parameters
tableTable to get the entries from

◆ toStack()

SL_SYMBOL void SL::Table::toStack ( State L) const

Dump all the map information onto the given Lua stack.

Parameters
LThe Lua state to dump the table onto

The documentation for this struct was generated from the following file: