1.. _tables: 2 3 4================= 5Tables 6================= 7 8.. index:: 9 single: Tables 10 11Tables are associative containers implemented as pairs of key/value (called slot); values 12can be any possible type and keys any type except 'null'. 13Tables are squirrel's skeleton, delegation and many other features are all implemented 14through this type; even the environment, where "global" variables are stored, is a table 15(known as root table). 16 17------------------ 18Construction 19------------------ 20 21Tables are created through the table constructor (see :ref:`Table constructor <table_constructor>`) 22 23------------------ 24Slot creation 25------------------ 26 27.. index:: 28 single: Slot Creation(table) 29 30Adding a new slot in a existing table is done through the "new slot" operator ``<-``; this 31operator behaves like a normal assignment except that if the slot does not exists it will 32be created.:: 33 34 local a = {} 35 36The following line will cause an exception because the slot named 'newslot' does not exist 37in the table 'a':: 38 39 a.newslot = 1234 40 41this will succeed: :: 42 43 a.newslot <- 1234; 44 45or:: 46 47 a[1] <- "I'm the value of the new slot"; 48 49----------------- 50Slot deletion 51----------------- 52 53.. index:: 54 single: Slot Deletion(table) 55 56 57:: 58 59 exp:= delete derefexp 60 61Deletion of a slot is done through the keyword delete; the result of this expression will be 62the value of the deleted slot.:: 63 64 a <- { 65 test1=1234 66 deleteme="now" 67 } 68 69 delete a.test1 70 print(delete a.deleteme); //this will print the string "now" 71 72