tableライブラリ
ライブラリ日本語解説あり
ひとことで言うと
テーブル(配列や辞書)を扱うためのライブラリです。値の追加・削除・並べかえなどができます。
公式の説明(英語):A library of table functions.
使用例
Script置く場所:ServerScriptService
local fruits = { "りんご", "バナナ", "みかん" }
print(fruits[1])
table.insert(fruits, "ぶどう")
print(#fruits)
for index, fruit in ipairs(fruits) do
print(index, fruit)
endスクリプトは、Luauの型チェック(luau-lsp)で確認しています。
関数(15)
| 名前と書き方 | 説明 |
|---|---|
cleartable.clear(table: table): () | テーブルを空にします。Sets all keys in the given table to nil. |
clonetable.clone(t: table): table | テーブルを複製します。Returns a shallow copy of the provided table. |
concattable.concat(t: Array, sep: string, i: int, j: int): string | 配列の値を文字列としてつなげます。Returns the given range of table elements as a string where each element is separated by the given separator. |
createtable.create(count: number, value: Variant): table | Returns a new table populated with many instances of the specified value. |
findtable.find(haystack: table, needle: Variant, init: number): Variant | 値を探して、その番号を返します。Returns the index of the first occurrence of needle within haystack starting from init. |
freezetable.freeze(t: table): table | Makes the given table read-only. |
inserttable.insert(t: Array, pos: number, value: Variant): () | テーブルに値を追加します。Inserts the provided value to the target position of the array. |
inserttable.insert(t: Array, value: Variant): () | テーブルに値を追加します。Appends the provided value to the end of the array. |
isfrozentable.isfrozen(t: table): bool | Returns true if the given table is frozen and false if it isn't frozen. |
maxntable.maxn(t: table): number | Returns the maximum numeric key of the provided table, or zero if the table has no numeric keys. |
movetable.move(src: table, a: number, b: number, t: number, dst: table): table | Copies the specified range of elements from one table to another. |
packtable.pack(values...: Variant): Variant | Returns a new table containing the provided values. |
removetable.remove(t: Array, pos: number): Variant | テーブルから値を取り除いて返します。Removes the specified element from the array, shifting later elements down to fill in the empty space if possible. |
sorttable.sort(t: Array, comp: function): () | テーブルを並べかえます。Sorts table elements using the provided comparison function or the < operator. |
unpacktable.unpack(list: table, i: number, j: number): Tuple | Returns all elements from the given list as a tuple. |
tableを使う記事
英語の説明とメンバーの一覧は、Roblox Creator Documentation(table)をもとにしています(CC BY 4.0)。日本語の解説は、このサイトで独自に書いたものです。