Data Table

Simple wrapper for the am::util::data::Table class. Allows for storing and retrieving tables of primative data, including other tables, numbers, booleans and strings. While values like numbers, strings, booleans and nil remain essentially unchanged when they are added to a data table, tables do change. Tables are turned into DataTables, which being a custom class means that normal table functions will not work. All values should remain the same however.
Return to Index
new ( )
__gc ( )
__eq ( DataTable rhs ) -> ( boolean )
__len ( ) -> ( integer )
at ( string key ) -> ( primative )
at ( string key , primative value ) -> ( DataTable )
push ( primative... values ) -> ( DataTable )
pairs ( function handler ) -> ( DataTable )
ipairs ( function handler ) -> ( DataTable )
remove ( string... keys ) -> ( DataTable )
new ( )
Creates a new DataTable with no data.
__gc ( )
Releases the reference counter on the DataTable.
__eq ( DataTable rhs ) -> ( boolean )
Compares this data table with another data table object.
Parameters:
DataTable rhs : The other data table to compare with.
Returns:
boolean : True if they are the same object.
__len ( ) -> ( integer )
Returns the number of key values in the data table. This is an implementation of the __len metamethod as such the Lua # operator can be used to get the size.
Returns:
integer : The number of key values in the data table.
at ( string key ) -> ( primative )
Returns the value associated with the given key. A primative is a number, string, boolean, nil or table of primatives.
Parameters:
string key : The key to look up.
Returns:
primative : The value.
at ( string key , primative value ) -> ( DataTable )
Sets the value at the given key. A primative is a number, string, boolean, nil or table of primatives.
Parameters:
string key : The key to set.
primative value : The value to set.
Returns:
DataTable : This
push ( primative... values ) -> ( DataTable )
Pushes a value or list of primatives on to the end of this data table. A primative is a number, string, boolean, nil or table of primatives.
 DataTable = import("DataTable")
 array = DataTable.new()
 array:push(5)
 am_log("Size 1: " .. #array)		-- Outputs: Size 1: 1
 
 array:push("String", true)
 am_log("Size 2: " .. #array)		-- Outputs: Size 2: 3
Parameters:
primative... values : The list of values to push on to the end.
Returns:
DataTable : This
pairs ( function handler ) -> ( DataTable )
The pairs function provides similar functionality to that of the Lua pairs function. The pairs function takes a function as it's argument and that function will be called once per key/value in the data table. If that function returns false then the loop is stopped.
 DataTable = import("DataTable")
 table = DataTable.new()
 table:at("num", 5)
 table:at("str", "String")
 table:at("bool", true)
 table:at(1, "one")
 table:at(2, "two")
 table:pairs(function(key, value)\n
     am_log(key .. " = ", value)
 end)
 -- The output order is not gurrantied
 -- 1 = "one"
 -- 2 = "two"
 -- "num" = 5
 -- "str" = "String"
 -- "bool" = true
Parameters:
function handler : The each function handler.
Returns:
DataTable : This
ipairs ( function handler ) -> ( DataTable )
The ipairs function provides similar functionality to that of the Lua ipairs function. The ipairs function takes a function as it's argument and that function will be called once per index/value in the data table. If that function returns false then the loop is stopped.
 DataTable = import("DataTable")
 table = DataTable.new()
 table:push("one", "two", 3)
 table:ipairs(function(index, value)\n
     am_log(index .. " = ", value)
 end)
 -- The output order is not gurrantied
 -- 1 = "one"
 -- 2 = "two"
 -- 3 = 3
Parameters:
function handler : The each function handler.
Returns:
DataTable : This
remove ( string... keys ) -> ( DataTable )
Removes the keys given list of strings. This takes a variable number of arguments which will be validated as being strings before a key is removed. It is not considered an error to remove a key that does not exist.
 DataTable = import("DataTable")
 table = DataTable.new()
 table:at("num", 5)
 table:at("str", "String")
 table:at("bool", true)
 
 am_log("Size 1: " .. #table)	-- Outputs: Size 1: 3
 table:remove("num", "bool")
 
 am_log("Size 2: " .. #table)	-- Outputs: Size 2: 1
Parameters:
string... keys : The keys to remove.
Returns:
DataTable : This