Template repo for tiny cross-platform apps that can be modified on phone, tablet or computer.
at main 69 lines 4.0 kB view raw
1{ 2 {type='rows', default={font={size=21}, line_height=25}, 3 {type='text', font={size=28}, line_height=50, 4 {'Lua@{Lua} > tables', 5 attrs={ 6 Lua={target='--lua'}, 7 }}, 8 }, 9 {type='filler', height=15}, 10 {type='text', "As tabelas do Lua são uma forma versátil de agrupar dados de maneiras que facilitam fatiar e cortar."}, 11 {type='filler', height=15}, 12 {type='text', '{} é um valor/expressão de tabela vazia.'}, 13 {type='filler', height=10}, 14 {type='text', 15 {'h = {11, 12, 13} cria um em@{array}, uma tabela que pode ser consultada por em@{chaves} numéricas.', 16 attrs={ 17 em={font={italic=true}}}}}, 18 {type='text', ' h[1] agora é 11, h[2] é 12 e assim por diante.'}, 19 {type='filler', height=10}, 20 {type='text', 'h = {a=34} cria uma tabela que pode ser consultada por chaves string.'}, 21 {type='text', " h['a'] agora é 34, h['b'] é 35."}, 22 {type='text', ' Você também pode abreviar chaves string constantes usando pontos. h.a é 34, h.b é 35.'}, 23 {type='filler', height=10}, 24 {type='text', 'se h for um array. #h é uma expressão que retorna o comprimento de h'}, 25 {type='text', " Chaves string não contam para o comprimento de um array."}, 26 {type='text', ' Arrays também param no primeiro slot ausente/nil. O comprimento de {1, 2, nil, 4} é 2.'}, 27 {type='filler', height=15}, 28 {type='text', 'Algumas funções úteis operando em tabelas:', font_size=28}, 29 {type='filler', height=15}, 30 {type='text', 'pairs(h)', font={size=24}}, 31 {type='text', 32 {' Retorna um em@{iterador}, um tipo de função, que permite convenientemente percorrer todas as chaves de uma tabela.', 33 attrs={ 34 em={font={italic=true}}}}}, 35 {type='text', ' Por exemplo, este programa vai imprimir o conteúdo de uma tabela: for key, value in pairs(h) do print(key, value) end'}, 36 {type='filler', height=15}, 37 {type='text', 'Algumas funções úteis operando em arrays:', font_size=28}, 38 {type='filler', height=15}, 39 {type='text', 'ipairs(h)', font={size=24}}, 40 {type='text', " Retorna um iterador que permite convenientemente percorrer índices e elementos de um array."}, 41 {type='text', ' Por exemplo, este programa vai imprimir o conteúdo de um array: for _, x in ipairs(h) do print(x) end'}, 42 {type='filler', height=10}, 43 {type='text', 'table.insert(h, value)', font={size=24}}, 44 {type='text', ' Adiciona um valor ao final do array h.'}, 45 {type='filler', height=10}, 46 {type='text', 'table.insert(h, index, value)', font={size=24}}, 47 {type='text', ' Insere um valor no índice no meio do array h.'}, 48 {type='filler', height=10}, 49 {type='text', 'table.remove(h)', font={size=24}}, 50 {type='text', ' Remove o valor no índice final do array h.'}, 51 {type='filler', height=10}, 52 {type='text', 'table.remove(h, index)', font={size=24}}, 53 {type='text', ' Remove o valor no índice no meio do array h, compactando valores posteriores para cima.'}, 54 {type='filler', height=10}, 55 {type='text', 'table.sort(h)', font={size=24}}, 56 {type='text', ' Ordena os elementos no array h.'}, 57 {type='filler', height=10}, 58 {type='text', 'table.sort(h, f)', font={size=24}}, 59 {type='text', ' Ordena os elementos no array h por uma função de comparação personalizada f.'}, 60 {type='text', ' f precisa aceitar 2 argumentos e retornar true se o primeiro for menor que o segundo.'}, 61 {type='filler', height=10}, 62 {type='text', 'table.reverse(h)', font={size=24}}, 63 {type='text', ' Inverte a ordem dos elementos do array h para que o elemento final se torne o primeiro, etc.'}, 64 {type='filler', height=10}, 65 {type='text', 'table.concat(h)', font={size=24}}, 66 {type='text', ' Concatena todos os elementos do array h em uma única string e a retorna.'}, 67 {type='text', ' Todos os elementos devem ser strings.'}, 68 } 69}