Script Reference : Table

Tables are associative containers implemented as pairs of key/value (called a slot).

   
Constructors
Name Description
local a={} Creates an empty table.
local a= {
slot1="I'm the slot value"
}
A table constructor can also contain slots declaration.
local a= {
[1]="I'm the value"
}
An alternative syntax to create table.
local table= {
a=10,
b="string",
[10]={},
function bau(a,b) { return a+b; }
}
Mixed approach.
local x = {
"id": 1,
"name": "Foo",
"price": 123,
"tags": ["Bar","Eek"]
}
Table declaration using JSON Syntax.

New slot

Adding a new slot in a existing table is done through the "new slot" operator '<-'; this operator behaves like a normal assignment except that if the slot does not exists it will be created.

a.newslot <- 1234;
or
a[1] <- "I'm the value of the new slot";

Slot deletion

Deletion of a slot is done through the keyword delete; the result of this expression will be the value of the deleted slot.

a <- {
test1=1234
deleteme="now"
}
delete a.test1 //this will print the string "now"

 

Methods
Name Return Type Description
int len() integer Returns number of items in the table.
int clear()   Returns number of items in the table.

t.clear();

rawget(name) value of the slot Returns slot value. If slot with this name is exists, method will raise an exception.

local d=t.rawget("test1");
local d=t.rawget(1);

rawset(name,value)   Sets slot value. With this method it is possible to create new slot.

t.rawset(2,4);
t.rawset("dd","ccc");

rawdelete(name) value of the slot Deletes slot. Method returns value of the slot. Method does not raise an excpetion if slot is not exists.

local d=t.rawdelete(1);

rawin(name) bool Returns true if slot with this value is exists. false will be returned if slot is available

local b0=t.rawin(10);
local b1=t.rawin("test1");