{ {type='rows', default={font={size=21}, line_height=25}, {type='text', font={size=28}, line_height=50, {'Lua@{Lua} > テーブル', attrs={ Lua={target='--lua'}, }}, }, {type='filler', height=15}, {type='text', 'Luaのテーブルは、データを簡単にスライスしたり分割したりできるようにグループ化する多様な方法です。'}, {type='filler', height=15}, {type='text', '{}は空のテーブル値/式です。'}, {type='filler', height=10}, {type='text', {'h = {11, 12, 13}はem@{配列}、数値em@{キー}で検索できるテーブルを作成します。', attrs={ em={font={italic=true}}}}}, {type='text', ' h[1]は11、h[2]は12になります。'}, {type='filler', height=10}, {type='text', 'h = {a=34}は文字列キーで検索できるテーブルを作成します。'}, {type='text', " h['a']は34、h['b']は35になります。"}, {type='text', ' 定数文字列キーはピリオドを使って短縮できます。h.aは34、h.bは35。'}, {type='filler', height=10}, {type='text', 'hが配列の場合、#hはhの長さを返す式です'}, {type='text', ' 文字列キーは配列の長さにカウントされません。'}, {type='text', ' 配列は最初の欠損/nilスロットで停止します。{1, 2, nil, 4}の長さは2です。'}, {type='filler', height=15}, {type='text', 'テーブルを操作する便利な関数:', font_size=28}, {type='filler', height=15}, {type='text', 'pairs(h)', font={size=24}}, {type='text', {' テーブルのすべてのキーを便利にループできるem@{イテレータ}という関数の一種を返します。', attrs={ em={font={italic=true}}}}}, {type='text', ' 例:このプログラムはテーブルの内容を印刷します:for key, value in pairs(h) do print(key, value) end'}, {type='filler', height=15}, {type='text', '配列を操作する便利な関数:', font_size=28}, {type='filler', height=15}, {type='text', 'ipairs(h)', font={size=24}}, {type='text', ' 配列のインデックスと要素を便利にループできるイテレータを返します。'}, {type='text', ' 例:このプログラムは配列の内容を印刷します:for _, x in ipairs(h) do print(x) end'}, {type='filler', height=10}, {type='text', 'table.insert(h, value)', font={size=24}}, {type='text', ' 配列hの最後に値を追加します。'}, {type='filler', height=10}, {type='text', 'table.insert(h, index, value)', font={size=24}}, {type='text', ' 配列hの中間のインデックスに値を挿入します。'}, {type='filler', height=10}, {type='text', 'table.remove(h)', font={size=24}}, {type='text', ' 配列hの最後のインデックスの値を削除します。'}, {type='filler', height=10}, {type='text', 'table.remove(h, index)', font={size=24}}, {type='text', ' 配列hの中間のインデックスの値を削除し、後の値を前に詰めます。'}, {type='filler', height=10}, {type='text', 'table.sort(h)', font={size=24}}, {type='text', ' 配列hの要素をソートします。'}, {type='filler', height=10}, {type='text', 'table.sort(h, f)', font={size=24}}, {type='text', ' カスタム比較関数fによって配列hの要素をソートします。'}, {type='text', ' fは2つの引数を受け取り、最初が2番目より小さい場合trueを返す必要があります。'}, {type='filler', height=10}, {type='text', 'table.reverse(h)', font={size=24}}, {type='text', ' 配列hの要素の順序を反転し、最後の要素が最初になります。'}, {type='filler', height=10}, {type='text', 'table.concat(h)', font={size=24}}, {type='text', ' 配列hのすべての要素を単一の文字列に結合して返します。'}, {type='text', ' すべての要素は文字列である必要があります。'}, } }