標準ライブラリ

利用できる標準ライブラリは次のモジュールに限定されています: 基本関数・math・string・table・bit32、 そしてテーブル反復子(pairs / ipairs / next)・メタテーブル・エラー処理です。

ioosdebugcoroutinepackagerequiredofileffi などは使えません。ファイルアクセスは無効化されています。

基本関数

グローバルに直接呼べる関数です。

type, tostring, tonumber, select, error, assert, print,
ipairs, pairs, next, unpack,
setmetatable, getmetatable, rawget, rawset, rawequal, rawlen,
pcall, xpcall
関数説明
type(v)値の型名を文字列で返す
tostring(v)文字列へ変換
tonumber(v [, base])数値へ変換。変換できなければ nil
select(n, ...)可変長引数の n 番目以降、または "#" で個数
error(msg)エラーを発生させる
assert(v [, msg])v が偽ならエラー
pcall(f, ...)f を保護モードで呼び、成否と結果を返す
xpcall(f, handler, ...)エラーハンドラ付きの保護呼び出し
ipairs(t) / pairs(t)テーブルの反復子
setmetatable / getmetatableメタテーブルの設定・取得
rawget / rawset / rawequal / rawlenメタメソッドを介さない素の操作

math

abs, ceil, cos, exp, floor, fmod, huge, log, max, min, modf, pi,
random, randomseed, sin, sqrt, tan, atan, atan2, deg, rad,
ldexp, frexp, sinh, cosh, tanh, type, tointeger, maxinteger, mininteger
関数 / 定数説明
math.pi円周率
math.huge正の無限大
math.abs(x)絶対値
math.floor(x) / math.ceil(x)切り捨て / 切り上げ
math.min(...) / math.max(...)最小 / 最大
math.sqrt(x)平方根
math.sin/cos/tan(x)三角関数(引数はラジアン)
math.atan(x) / math.atan2(y, x)逆正接
math.deg(x) / math.rad(x)ラジアン↔度
math.exp(x) / math.log(x)指数 / 自然対数
math.fmod(x, y)剰余
math.modf(x)整数部と小数部を返す
math.ldexp(m, e) / math.frexp(x)仮数・指数の操作
math.sinh/cosh/tanh(x)双曲線関数
math.random([m [, n]])乱数。後述の注意あり
math.randomseed(x)乱数シードの設定
math.type(x)数値の種別を返す
math.tointeger(x)整数化できれば整数、できなければ nil
math.maxinteger / math.mininteger整数の上限・下限
math.random は実行のたびに現在のフレーム番号でシードが設定されます。 そのため同じフレームの再描画では同じ結果になりますが、1 回の実行の中で連続して呼ぶと値は進みます。 オブジェクトやフレームに対して安定した乱数が必要なときは anim.randanim.noiseobj.rand を使ってください。

string

format, len, sub, upper, lower, rep, reverse, find, match,
gmatch, gsub, byte, char, dump, pack, unpack, packsize
関数説明
string.format(fmt, ...)書式付き文字列。例: string.format("%.2f", x)
string.len(s)長さ(#s と同じ)
string.sub(s, i [, j])部分文字列
string.upper(s) / string.lower(s)大文字 / 小文字
string.rep(s, n)n 回繰り返した文字列
string.reverse(s)反転
string.find(s, pat)パターン検索
string.match(s, pat)パターンに一致した部分を返す
string.gmatch(s, pat)一致を順に返す反復子
string.gsub(s, pat, repl)置換
string.byte(s [, i]) / string.char(...)文字コード↔文字
string.pack/unpack/packsizeバイナリのパック・アンパック

table

insert, remove, sort, concat, unpack, move
関数説明
table.insert(t, [pos,] v)要素を追加・挿入
table.remove(t [, pos])要素を削除して返す
table.sort(t [, comp])並べ替え
table.concat(t [, sep])文字列に連結
table.unpack(t)テーブルを複数の値に展開
table.move(a1, f, e, t [, a2])要素の移動・コピー

bit32

32 ビット整数のビット演算ライブラリです。

band, bor, bxor, bnot, lshift, rshift, arshift,
extract, replace, btest, countlz, countrz
関数説明
bit32.band(...)ビット積
bit32.bor(...)ビット和
bit32.bxor(...)排他的論理和
bit32.bnot(x)ビット反転
bit32.lshift(x, n) / bit32.rshift(x, n)左 / 右シフト
bit32.arshift(x, n)算術右シフト
bit32.extract(n, f [, w])ビット列の取り出し
bit32.replace(n, v, f [, w])ビット列の置き換え
bit32.btest(...)ビット積が 0 でないか
bit32.countlz(x) / bit32.countrz(x)先頭 / 末尾の 0 ビット数
← Lua の基礎 構文拡張 →