テーブル

ディクショナリまたは配列を、Luaのテーブルとして使用できます。

配列は、インデックスが自動的に割り当てられ、最初の値のインデックスが1である特別なディクショナリです。“#”演算子は、配列に対しても機能しますが、ディクショナリなどのテーブルでは正しい値が得られないことが普通です。

FekoLua機能としてinspect関数が用意されていて、テーブルの内容を容易に確認できます。

an_array = {1,1,2,3,5,8,13}
print(#an_array) -- prints "7"
print(an_array[3]) -- prints "2"
a_table = {[ ' bread ' ] = "brown", [ ' eggs ' ] = 10} -- tables are dictionaries or arrays
print(a_table[ ' bread ' ]) -- "prints brown"
print(a_table) -- prints "table: 0x7f63c8001200", the memory location of the table
inspect(a_table) -- prints the contents of the table
print(#a_table) -- prints "0" since it is not an array (take note)