Testing Lua array/table operations

Array (table with numerical index)

Array Init

simple:                   GET,POST,PUT,DELETE (4)
predefined:               HTTP,FTP,NNTP,IRC,[7] = 'FTPS' (5)
initialized:              html,head,body (3)
generated 1:              a,b,i,p,u (5)
generated 2:              hr,br,p,span,div (5)
original:                 aa,bb,cc,gg,zz (5)
assigned:                 aa,bb,cc,gg,zz (5)
function call:            ff0,ff1,F3 (3)
function return:          1,2,3,[4] = 
{ ff0,ff1,F3 } (4)
multi-dimensional:        3.1428571428571,TLDs,[3] = 
{ com,org,net,int },
[4] = 
{ edu,mil,gov },
[5] = function: 003287F8, [6] = 42 (6)

Array Access

PUT
NNTP
body
org
[2] is: FTP
[100] is: nil

Array Operations

array:                    HTTP,FTP,NNTP,IRC,[7] = 'FTPS', [8] = 'POP3', [9] = 'Z1', [10] = 'Z2' (8)
getn:                     10
type=='table':            true

sort:                     FTP,FTPS,HTTP,IRC,NNTP,POP3,Z1,Z2 (8)
remove (pop):             FTP,FTPS,HTTP,IRC,NNTP,POP3,Z1 (7)
(reverse):                Z1,POP3,NNTP,IRC,HTTP,FTPS,FTP (7)
remove 1 (shift):         POP3,NNTP,IRC,HTTP,FTPS,FTP (6)
(replace) 1:              HTTPS,NNTP,IRC,HTTP,FTPS,FTP (6)
Splice 2 2 s:             HTTPS,messaging,HTTP,FTPS,FTP (5) 'NNTP,IRC' removed
Splice 4 1:               HTTPS,messaging,HTTP,FTP (4) 'FTPS' removed
Splice 2 0 s s:           HTTPS,POP3,IMAP4,messaging,HTTP,FTP (6) '' removed
insert Y Z (push):        HTTPS,POP3,IMAP4,messaging,HTTP,FTP,Y,Z (8)
insert B A (unshift):     A,B,HTTPS,POP3,IMAP4,messaging,HTTP,FTP,Y,Z (10)
slice 3 7:                HTTPS,POP3,IMAP4,messaging (4)
slice 7:                  HTTP,FTP,Y,Z (4)
slice 3 -2:               HTTPS,POP3,IMAP4,messaging,HTTP,FTP (6)
(concat/merge) a1 a2 a3:  HTTPS,POP3,IMAP4,messaging,HTTP,FTP,GET,POST,PUT,DELETE,html,head,body (13)
No native search in values, just iterate on array to search
concat ' | ':             HTTPS | POP3 | IMAP4 | messaging | HTTP | FTP | GET | POST | PUT | DELETE | html | head | body

Array Iteration

for ipairs:               [1] HTTPS, [2] POP3, [3] IMAP4, [4] messaging, [5] HTTP, [6] FTP, [7] GET, [8] POST, [9] PUT, [10] DELETE, [11] html, [12] head, [13] body, 
for pairs:                [1] HTTPS, [2] POP3, [3] IMAP4, [4] messaging, [5] HTTP, [6] FTP, [7] GET, [8] POST, [9] PUT, [10] DELETE, [11] html, [12] head, [13] body, 

Associative array

Associative Array Init

simple:                   one = '1', three = '3_3_3', ['#@!\%'] = 'garbage', two = '2_2' (4)
literal:                  one = 'un_uno_ichi', ['and... more'] = '...', three = 'trois_tres_san', two = 'deux_dos_ni' (4)
id:                       one = '1', uno = true, ichi = '', un = 1 (4)
obj:                      in first numerical slot,in numerical slot after last one,[5] = function: 003287F8, __ = 
{ 4,2 },
['1, 3.14'] = '1, 3.1428571428571', _ = 
{ one = '1', uno = true, ichi = '', un = 1 },
[3.14159] = 
{ aa,bb,cc,gg,zz } (7)
nested:                   deep = 
{ into = 
{ table = '!' } } (1)

Associative Array Access

2_2
3_3_3
garbage
nil
nil
true
!

Associative Array Operations

(add):                    1,['and... more'] = '...', ['+-/*'] = 'ops', two = 'deux_dos_ni', three = 'trois_tres_san', newOne = 'New entry', one = 'un_uno_ichi' (7)
(delete):                 ['+-/*'] = 'ops', three = 'trois_tres_san', newOne = 'New entry', one = 'un_uno_ichi' (4)

View source of script generating this page / Get source of script