組み込み用のスクリプト言語として使えるLua はライトな反面、動的型付けや 1-based index といった仕様がボトルネックになりがちです。そうした状況の中、相応の短所も抱えた Lua の代替となりえる C/C++ 開発用組み込み用のスクリプト言語が多く開発されています。しかしながら、それらを横並びで比較及び評価した記事をあまり見かけませんでした。そこで、本記事では AltLua となりうる言語を取り上げ、それぞれの特徴を検証していきます。
コンパイルして Lua を出力するトランスパイラ言語について。Lua VM 上で動作するため、既存の Lua ライブラリの利用が可能な他、軽量で高速な強みを十分に生かせることが期待できます。
github stars やリリースなどの情報は 2025 年現時点のものを記載します。
https://github.com/leafo/moonscript
コード例:
classThing name:"unknown"classPerson extends Thing say_name:=> print"Hello, I am #{@name}!"with Person!.name="MoonScript" \say_name!importconcat, insert from tabledouble_args=(...)->[x*2for x in*{...}]tuples=[{k, v}for k,v in ipairs my_table]https://github.com/bakpakin/Fennel
;; Sample: read the state of the keyboardand move the playeraccordingly(local dirs{:up[0-1]:down[01]:left[-10]:right[10]})(each[key[dx dy](pairs dirs)](when(love.keyboard.isDown key)(let[[px py] playerx(+px(* dx player.speed dt))y(+py(* dy player.speed dt))](world:move player x y))))https://github.com/teal-language/tl
local addsub={}function addsub.add(a: number, b: number): numberreturn a+ bendfunction addsub.sub(a: number, b: number): numberreturn a- bendreturn addsublocal enum State"open""closed"end-- a record: a table with a known set of fieldslocal record Point x: number y: numberendhttps://github.com/IppClub/YueScript
-- import syntaximport"yue" as:p,:to_lua-- object literalsinventory= equipment:*"sword"*"shield" items:* name:"potion" count:10* name:"bread" count:3-- pipe operator[1,2,3]|>map(x)-> x*2|>filter(x)-> x>4|> reduce0,(a, b)-> a+ b|> print-- metatable manipulationapple= size:15<index>: color:0x00ffffwith apple p.size,.color,.<index>if.<>?-- js-like export syntaxexport 🌛="月之脚本"https://github.com/TypeScriptToLua/TypeScriptToLua
// Give points to all friends around the target positionfunctiononAbilityCast(caster: Unit, targetPos: Vector){const units=findUnitsInRadius(targetPos,500);const friends= units.filter(unit=> caster.isFriend(unit));for(const friendof friends){ friend.givePoints(50);}}// ⬇️ ts to lua-- Give points to all friends around the target positionfunctiononAbilityCast(caster, targetPos) local units=findUnitsInRadius(targetPos,500) local friends=__TS__ArrayFilter( units,function(____, unit)return caster:isFriend(unit) end)for ____, friendinipairs(friends)do friend:givePoints(50) endend以下は、複数のプログラミング言語にトランスパイルすることを目的として開発された斬新なプログラミング言語です。ターゲットの一つとして Lua が使えます。
https://github.com/HaxeFoundation/haxe
https://github.com/Tencent/ScriptX
以下は Lua インスパイアの言語ですが、aot コンパイルの言語です。スクリプティングには使用できません。
| 言語名 | GitHub Stars | 現在の開発状況 | 特徴 |
|---|---|---|---|
| MoonScript | 3.3k | 🌑 | Python-like |
| Fennel | 2.6k | 🌗 | LISP系の関数型 |
| Teal | 2.3k | 🌕 | 静的型付け Lua dialect |
| YueScript | 500 | 🌕 | MoonScript diarect |
| TypeScriptToLua | 2.3k | 🌕 | TypeScript で書ける |
| Haxe | 6.4k | 🌕 | 「多言語トランスパイラ」 |
| ScriptX | 500 | 🌗 | 「スクリプト抽象化レイヤー」 |
Lua と関わりのない組み込み向けスクリプト言語にも、強力かつ柔軟な選択肢がいくつか存在します。ここでは代表的な言語を紹介します。
https://www.angelcode.com/angelscript/
// Include the shared code#include'shared.as'// This script implements the logic for the player characterclassCPlayer:IController{// The constructor must take a CGameObj handle as input,// this is the object that the script will controlCPlayer(CGameObj @obj){// Keep the owner for later reference@self= obj;}voidOnMessage(ref @m,const CGameObj @sender){CMessage @msg=cast<CMessage>(m);if( msg!is null&& msg.txt=='Attack'){// The zombie got usself.Kill();game.EndGame(false);}}CGameObj @self;}AngelScript は Lua よりも細かい制御が可能で、よりハードウェアに近いレイヤーの表現が可能です。例えば、数値型について全てを double 値 (64-bit) として取り扱う Lua に対し、AngelScript では int8~uint64 まで細かく指定出来るためメモリ使用量の節約が期待できます。オブジェクト型についても、それぞれについて GC の対象とするかどうかをコンパイル段階で管理しているためパフォーマンスの向上が見込めます。
これらの優位性はゲーム開発に寄与する重要な要素となります。以前の記事でも取り上げましたが、Hazelight Studios は Unreal Engine 5 に AngelScript を導入した独自フォークを開発しています[1]。AngelScript の導入は単に開発イテレーションの質が高まっただけでなく、パフォーマンス的にも高水準なようです。UE 向け Lua プラグインと AngelScript のベンチマーク測定に関する資料を確認したため以下に掲載します。この結果によると、 AngelScript は Blueprint と Lua に大きく差をつけ、C++ と遜色ないほどの性能を発揮しています。
https://github.com/straywriter/UnrealEngine-Angelscript-Performance


https://github.com/rhaiscript/rhai
拡張性も充実していそうで、今後 Rust プロジェクトの機会があれば使ってみるといいかもしれません。しかし、ある程度性能があるとはいえ、ゲームロジックを Rhai で全て実装するのは推奨されず、代わりに Lua を使ってほしいと明記されていました…[2]
// This Rhai script calculates the n-th Fibonacci number using a// really dumb algorithm to test the speed of the scripting engine.constTARGET=28;constREPEAT=5;constANSWER=317_811;fnfib(n){if n<2{ n}else{fib(n-1)+fib(n-2)}}print(`Running Fibonacci(${TARGET}) x${REPEAT} times...`);print("Ready... Go!");let result;let now=timestamp();for nin0..REPEAT{ result=fib(TARGET);}print(`Finished. Run time =${now.elapsed} seconds.`);print(`Fibonacci number #${TARGET} =${result}`);if result!=ANSWER{print(`The answer is WRONG! Should be${ANSWER}!`);}https://github.com/pocketpy/pocketpy
pocketpy というゲームスクリプティング向けの軽量 Python インタプリタが開発されているようです。
2023年から開発されているようで比較的新しい
本家の実装である CPython と同じくらい高速らしい
V8 が組み込みに不向きとはいえ、軽量JS のプロジェクトを調べてみると一定数ありました。やはり需要があるようで予想以上にありました。以下にアクティブな3つを掲載します。
https://github.com/svaarala/duktape
https://github.com/jerryscript-project/jerryscript
https://github.com/quickjs-ng/quickjs
最近はやや開発が緩やかに見受けられますが、参考までに紹介します。
https://github.com/albertodemichelis/squirrel
https://github.com/wren-lang/wren
https://github.com/ChaiScript/ChaiScript
https://github.com/JoeStrout/miniscript
https://github.com/marcobambini/gravity
今回取り上げきれなかった言語も多くあるかと思いますが、本記事が何かしらの参考になれば幸いです。
自分としては、Lua プロジェクトにおいては Teal、C++ ゲーム開発においては AngelScript、Rust 関連をする機会があれば Rhai を使ってみたいという気持ちになりました。
