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)

名前と書き方説明
clear
table.clear(table: table): ()
テーブルを空にします。Sets all keys in the given table to nil.
clone
table.clone(t: table): table
テーブルを複製します。Returns a shallow copy of the provided table.
concat
table.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.
create
table.create(count: number, value: Variant): table
Returns a new table populated with many instances of the specified value.
find
table.find(haystack: table, needle: Variant, init: number): Variant
値を探して、その番号を返します。Returns the index of the first occurrence of needle within haystack starting from init.
freeze
table.freeze(t: table): table
Makes the given table read-only.
insert
table.insert(t: Array, pos: number, value: Variant): ()
テーブルに値を追加します。Inserts the provided value to the target position of the array.
insert
table.insert(t: Array, value: Variant): ()
テーブルに値を追加します。Appends the provided value to the end of the array.
isfrozen
table.isfrozen(t: table): bool
Returns true if the given table is frozen and false if it isn't frozen.
maxn
table.maxn(t: table): number
Returns the maximum numeric key of the provided table, or zero if the table has no numeric keys.
move
table.move(src: table, a: number, b: number, t: number, dst: table): table
Copies the specified range of elements from one table to another.
pack
table.pack(values...: Variant): Variant
Returns a new table containing the provided values.
remove
table.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.
sort
table.sort(t: Array, comp: function): ()
テーブルを並べかえます。Sorts table elements using the provided comparison function or the < operator.
unpack
table.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)。日本語の解説は、このサイトで独自に書いたものです。

執筆:鈴木孝昌官公庁のWeb・システム開発を担当する現役プロジェクトマネージャー。沖縄マイクラ部 クロスウェーブで、ロブロックス(Roblox)・マインクラフト(マイクラ)・Scratchなどのプログラミングを指導。マイクラカップ沖縄代表チームを指導(第6回・第7回、第7回TBS賞)。
沖縄マイクラ部で、子どもたちにロブロックス(Roblox)やマインクラフト(マイクラ)のプログラミングを教えています。プロフィールと編集方針
Instagramで教室の様子を見る
noteで記事を読む