コミットを比較
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
|
|
f26816343f
|
||
|
|
0cab8972e0
|
||
|
|
f2aa668cf6
|
||
|
|
ed27979f64
|
||
|
|
7b958ea171
|
||
|
|
332dab3889
|
||
|
|
75d457a7ab
|
||
|
|
50e1801878
|
||
|
|
793d010bdb
|
||
|
|
b564b0b185
|
||
|
|
6d83fe93d8
|
||
|
|
db9c3747ea
|
||
|
|
7d887afe5a
|
||
|
|
ac34830367
|
||
|
|
8ed188d0e2
|
||
|
|
9c55c08caf
|
||
|
|
42868023f3
|
||
|
|
e146b36fa0
|
||
|
|
5fac495848
|
||
|
|
4fd519249f
|
||
|
|
1b26df959f
|
||
|
|
3cd67212a1
|
||
|
|
46692dfe95
|
||
|
|
e8d9cef129
|
||
|
|
18036cd74e
|
||
|
|
c8f857d2b4
|
||
|
|
ac7f797566
|
||
|
|
8beae1a277
|
||
|
|
6eb4d7c9af
|
||
|
|
a843f460de
|
||
|
|
27f04c7560
|
||
|
|
43c0ce88b3
|
||
|
|
00f0d991c1
|
||
|
|
784d294ca6
|
||
|
|
260d427bcf
|
||
|
|
b62f4a3a7d
|
||
|
|
79a408cafd
|
||
|
|
807df7df8a
|
||
|
|
0c5e3066c1
|
||
|
|
fbaff95503
|
||
|
|
8dec38a911
|
||
|
|
902d729c19
|
||
|
|
79f8ff8839
|
||
|
|
9a630ecb5a
|
||
|
|
d9e6132a1f
|
||
|
|
e685e7aa40
|
||
|
|
bf49fe9984
|
||
|
|
c05a1479f9
|
||
|
|
80ddb663b0
|
||
|
|
2f1bbc3828
|
||
|
|
e911f6e83f
|
||
|
|
6162ce5c19
|
検索条件に一致するファイルはありません
+25
-45
@@ -1,63 +1,43 @@
|
||||
# v1.13.2 - Lua スクリプト for YMM4
|
||||
# v1.13.4 - Lua スクリプト for YMM4
|
||||
|
||||
scene.set / scene.get の値の見え方を、フレーム位置に対して決定論的なモデルへ変更したリリースです。
|
||||
共有領域を「どのフレームで何を書き込んだか」を記録する履歴として再設計し、各フレームの読み取りは「そのフレームより前に確定した最新の値」を返すようにしました。これにより、タイムラインをどの順番でシークしても、同じフレームでは同じ値を読み取ります。あわせて、書き込みの確定に次のフレームの評価を必要としないようにし、同じフレームで複数のアイテムが同じ名前へ書き込んだ場合の優先規則を定め、動画出力とアイテムエフェクトの編集画面を編集中のプレビューから分離し、履歴が使うメモリへ上限を設けました。
|
||||
呼び出しの書き方と関数の引数に変更はありません。scene.set / scene.get を使わないスクリプトへの影響はありません。
|
||||
環境情報を取得する obj.getinfo を追加したリリースです。
|
||||
スクリプトの設置フォルダのパスや動画の出力状態に加えて、最大画像サイズ、BPMグリッドの情報、経過時間、本体のバージョンを名前で取得できます。MoonSharp とネイティブの両エンジンで同一の関数として動作します。
|
||||
あわせて、プラグインの内部構成を依存関係の層ごとの複数アセンブリへ分割し、Lua API の登録と入力補完をソースジェネレータによる宣言的な生成へ移行しました。既存のスクリプトの書き方と実行結果に変更はありません。
|
||||
|
||||
---
|
||||
|
||||
## 動作の変更
|
||||
## 新機能
|
||||
|
||||
### 1. 値の見え方をフレーム位置に対して決定論的なモデルへ変更
|
||||
### obj.getinfo による環境情報の取得
|
||||
|
||||
v1.13.1 までは、各アイテムの書き込みを保留領域へため、次のフレームの評価が行われた時点で共有領域の現在値へ反映していました。このため、読み取れる値が「どのフレームを評価してきたか」というシークの経路に左右され、前のフレームへ戻ったときに後のフレームで書き込まれた値が見えることがありました。
|
||||
今回から、書き込みをフレーム番号付きの履歴として記録し、scene.get は「自分のフレームより前に確定した最新の値」を返すようにしました。
|
||||
自分のスクリプトが書き込んだ値は、同じ実行の中で直後の scene.get からそのまま読み取れます。他のアイテムが書き込んだ値は、次のフレーム以降の評価から読み取れます。
|
||||
同じフレームの中では、アイテムがどの順番で評価されても scene.get が返す値は変わりません。
|
||||
obj.getinfo(名前) は、名前で指定した環境情報を返します。対応していない名前を指定した場合は nil を返します。取得できる情報は次のとおりです。
|
||||
|
||||
### 2. ランダムシークへの対応
|
||||
- "script_path" は、プラグインの設置フォルダのパスを返します。末尾には区切り文字が付きます。
|
||||
- "filter" は、フィルタ効果として処理中かどうかを返します。本プラグインでは常に true を返します。
|
||||
- "saving" は、動画を出力中のときだけ true を返します。
|
||||
- "image_max" は、最大画像サイズを横幅と高さの2つの値で返します。
|
||||
- "bpm" は、BPMグリッドのテンポと拍子と基準時間の3つの値を返します。基準時間の単位は秒です。BPMグリッドを設定していない場合はテンポが 0 になります。
|
||||
- "clock" は、YMM4 の起動からの経過時間を秒で返します。
|
||||
- "script_time" は、スクリプトの実行開始からの経過時間をミリ秒で返します。
|
||||
- "version" は、本体のバージョンを major×10000+minor×100+build の数値で返します。
|
||||
|
||||
タイムライン上をどの順番でシークしても、各フレームの読み取り結果は変わりません。
|
||||
前へ戻ったフレームでは、そのフレームより後に書き込まれた値は見えず、そのフレームより前に書き込まれた値だけが見えます。
|
||||
書き込んだフレームの直後のフレームを評価しなくても、それより後のどのフレームからでも読み取れます。
|
||||
同じフレームを何度再評価しても、読み取れる値と書き込みの結果は同一です。
|
||||
|
||||
### 3. 同じフレームで複数のアイテムが同じ名前へ書き込んだ場合の規則
|
||||
|
||||
同じフレームで複数のアイテムが同じ名前へ書き込んだ場合、レイヤー番号の大きいアイテムの書き込みが優先されます。
|
||||
アイテムは並列に評価されますが、この規則により結果は評価のタイミングに依存しません。
|
||||
同じアイテムの中で複数の Lua スクリプトエフェクトが同じ名前へ書き込んだ場合は、エフェクトチェーンの後段の書き込みが優先されます。
|
||||
|
||||
### 4. 動画出力とアイテムエフェクトの編集画面を編集中のプレビューから分離
|
||||
|
||||
動画出力は編集中のプレビューとは独立した空の共有領域から始まります。編集画面での試行の途中経過が出力へ持ち込まれることがなくなり、同じプロジェクトを出力すれば毎回同じ結果になります。出力が終わると、その出力で使った共有領域は破棄されます。
|
||||
アイテムエフェクトの編集画面のプレビューも独立した共有領域を使うため、編集画面を開いても編集中のプレビューの共有値は変化しません。
|
||||
現在のフレームの画像出力は編集中のプレビューと同じ共有領域を参照するため、保存される画像はプレビューの表示と一致します。v1.13.1 までは画像出力が共有領域を全消去していましたが、この副作用はなくなりました。
|
||||
|
||||
### 5. 履歴のメモリへ上限を追加
|
||||
|
||||
各名前の最新の値を除いた履歴が使うメモリは 16MB までとし、超過した場合は全体で最も古い記録から順に間引きます。最新の値は間引きの対象になりません。
|
||||
1 つのシーンに保存できる名前が 4096 個までである仕様は、v1.13.1 から変わりません。
|
||||
編集中のみプレビューへ枠を描き、出力時には描かないといった分岐へ利用できます。
|
||||
|
||||
---
|
||||
|
||||
## 互換性・後方互換
|
||||
|
||||
- 呼び出しの書き方と関数の引数に変更はありません。scene.set / scene.get を使わないスクリプトへの影響はありません。
|
||||
- スクリプトがエラーまたはタイムアウトで終了したフレームの書き込みを反映しない仕様は、v1.13.1 から変わりません。
|
||||
- 名前と文字列値を UTF-8 換算で 4095 バイトへ切り詰める仕様は、v1.13.0 から変わりません。
|
||||
- nil を渡した削除は、削除の記録として履歴へ残ります。削除より前のフレームでは削除前の値を、削除より後のフレームでは nil を読み取ります。
|
||||
- 共有値はメモリ上にのみ保持し、プロジェクトファイルには保存しません。YMM4 を終了すると失われます。
|
||||
- 既存のスクリプトの書き方と実行結果に変更はありません。obj.getinfo は新規の関数であり、従来の呼び出しへは影響しません。
|
||||
- obj.getinfo は MoonSharp とネイティブの両エンジンで動作します。script_path、filter、saving、image_max、bpm、version は両エンジンで同一の値を返します。clock と script_time は経過時間の計測であり、値そのものは実行のたびに変わります。
|
||||
- v1.13.3 までの仕様に変更はありません。
|
||||
|
||||
---
|
||||
|
||||
## 内部実装
|
||||
|
||||
- SceneSharedValues を世代スナップショット方式からフレーム索引付きの履歴方式へ再設計しました。名前ごとに「フレーム番号・レイヤー番号・値」の組をフレーム昇順で保持し、読み取りは自分のフレームより前の最新の組を二分探索で求めます。nil の書き込みは削除の記録として履歴へ残し、直前の値と同じ書き込みは記録しません。保留領域と世代の追跡、出力開始の検出によるリセットは撤廃しました。
|
||||
- 共有領域を描画パイプラインごとに分離しました。YMM4 は動画出力・画像出力・アイテムエフェクトの編集画面のそれぞれで専用のグラフィックデバイスを生成するため、デバイスのインスタンスを鍵とした ConditionalWeakTable で領域を引き当てることで、出力は毎回空の領域から始まり、出力の終了後は領域が GC で解放されます。編集中のプレビューはアプリケーションの実行中を通して同じデバイスを使うため、領域が維持されます。
|
||||
- 同じフレームの同じ名前への書き込みが競合した場合、レイヤー番号の大きい書き込みを採用し、同じレイヤーでは後から確定した書き込みで置き換えます。並列評価でも結果が発行順序に依存しません。
|
||||
- SceneValueSession の開始時にスコープとレイヤー番号を受け取るようにし、正常終了時の発行でフレーム番号とレイヤー番号を付けて履歴へ即時確定します。書き込みバッファと読み取りメモ化、参照の記録は従来どおりです。
|
||||
- LuaScriptEffectProcessor のフレームキャッシュの検証を履歴照合へ変更しました。記録した読み取り結果を現在のフレームの履歴と照合し、食い違うフレームでは再実行します。書き込みは履歴として保持され再発行が不要になったため、共有値を書き込んだフレームのキャッシュ再利用の禁止を撤廃しました。
|
||||
- 各名前の最新の組を除いた履歴のメモリ使用量を追跡し、16MB を超えた場合は全体で最も古い組から決定論的に間引きます。
|
||||
- NativeProtocol と worker.lua に変更はありません。ワーカーの実行内キャッシュのセマンティクスは新しいモデルとそのまま一致します。
|
||||
- テストは 3086 件です。v1.13.1 の 3080 件から、履歴の可視性とランダムシークの決定論、後戻りシークでの挿入、レイヤーによる競合解決、nil の削除記録、再発行の冪等性、履歴メモリの上限、スコープの分離の検証を追加しました。
|
||||
- プラグインを依存関係の層ごとに LuaScript.Kernel、LuaScript.Compat、LuaScript.Media、LuaScript.Runtime、および本体の 5 つのアセンブリへ分割しました。名前空間は据え置き、参照の向きを一方向へ整理しています。
|
||||
- Lua API の登録と毎フレームの変数投影を、属性から生成するソースジェネレータへ移行しました。入力補完の候補もこの宣言から生成し、手書きの一覧を廃止しました。関数を 1 つ追加すると、登録と補完へ自動的に反映されます。
|
||||
- Kernel、Compat、Runtime の各プロジェクトを 1 ファイル 1 クラスへ整理し、ドメインごとのフォルダへ再配置しました。エンジンのテーブル管理は LuaScope へ汎用化しています。
|
||||
- 映像デコーダを LuaScript.Media プロジェクトへ分離し、ツールバーを View と ViewModel へ分離しました。ViewModel はフレームワークに依存しない構成へ整理しています。
|
||||
- obj.getinfo の実装では、BPMグリッドの情報を YMM4 のシーンから取得し、script_path と version は本体からエンジンへ渡します。経過時間は両エンジンがそれぞれ高精度タイマーで計測します。
|
||||
- テストは 3113 件です。v1.13.3 の 3092 件から、obj.getinfo の両エンジンでの実行結果の検証と、補完カタログの回帰検証、およびエンジンのテーブルライフサイクルの特性化検証を追加しました。
|
||||
@@ -1,5 +1,5 @@
|
||||
========================================
|
||||
Luaスクリプト for YMM4 v1.13.2
|
||||
Luaスクリプト for YMM4 v1.13.4
|
||||
========================================
|
||||
YukkuriMovieMaker4(YMM4)上で動作する、Luaスクリプトで映像エフェクトのパラメータや
|
||||
ピクセルを直接制御できるプラグインです。
|
||||
|
||||
@@ -73,6 +73,10 @@ jobs:
|
||||
New-Item -ItemType Directory -Path "$stageRoot/LICENSE" -Force | Out-Null
|
||||
|
||||
Copy-Item "$outDir/LuaScript.dll" "$stageRoot/"
|
||||
Copy-Item "$outDir/LuaScript.Kernel.dll" "$stageRoot/"
|
||||
Copy-Item "$outDir/LuaScript.Compat.dll" "$stageRoot/"
|
||||
Copy-Item "$outDir/LuaScript.Media.dll" "$stageRoot/"
|
||||
Copy-Item "$outDir/LuaScript.Runtime.dll" "$stageRoot/"
|
||||
Copy-Item "$outDir/MoonSharp.Interpreter.dll" "$stageRoot/"
|
||||
Copy-Item "$outDir/native/luajit.exe" "$stageRoot/native/"
|
||||
Copy-Item "$outDir/native/lua51.dll" "$stageRoot/native/"
|
||||
|
||||
差分なしでファイル名を変更。
差分なしでファイル名を変更。
@@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>1.13.4</Version>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="LuaScript" />
|
||||
<InternalsVisibleTo Include="LuaScript.Runtime" />
|
||||
<InternalsVisibleTo Include="LuaScript.Tests" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\LuaScript.Kernel\LuaScript.Kernel.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="AviUtlCompatMap.xml" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -42,7 +42,7 @@ namespace LuaScript.Compat
|
||||
if (string.IsNullOrEmpty(script))
|
||||
return AviUtlEngine.AviUtl;
|
||||
|
||||
foreach (var raw in script.Replace("\r\n", "\n").Replace("\r", "\n").Split('\n'))
|
||||
foreach (var raw in ScriptParserHelper.SplitLines(script))
|
||||
{
|
||||
var line = raw.Trim();
|
||||
if (!line.StartsWith("--!", System.StringComparison.Ordinal))
|
||||
-5
@@ -2,11 +2,6 @@ using System.Collections.Generic;
|
||||
|
||||
namespace LuaScript.Compat
|
||||
{
|
||||
internal readonly record struct AviUtlParameterMapping(string Source, string Property, double Scale, double Offset)
|
||||
{
|
||||
public double Transform(double value) => value * Scale + Offset;
|
||||
}
|
||||
|
||||
internal sealed class AviUtlEffectMapping
|
||||
{
|
||||
private readonly Dictionary<string, AviUtlParameterMapping> _parameters;
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace LuaScript.Compat
|
||||
{
|
||||
internal enum AviUtlEngine
|
||||
{
|
||||
AviUtl,
|
||||
AviUtl2,
|
||||
Both,
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
namespace LuaScript.Compat
|
||||
{
|
||||
internal enum AviUtlEngine
|
||||
{
|
||||
AviUtl,
|
||||
AviUtl2,
|
||||
Both,
|
||||
}
|
||||
|
||||
internal static class AviUtlEngineExtensions
|
||||
{
|
||||
public static bool Includes(this AviUtlEngine scope, AviUtlEngine target) =>
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace LuaScript.Compat
|
||||
{
|
||||
internal readonly record struct AviUtlParameterMapping(string Source, string Property, double Scale, double Offset)
|
||||
{
|
||||
public double Transform(double value) => value * Scale + Offset;
|
||||
}
|
||||
}
|
||||
差分なしでファイル名を変更。
+3
-34
@@ -43,26 +43,8 @@ namespace LuaScript.Compat
|
||||
if (string.IsNullOrEmpty(source))
|
||||
return layout;
|
||||
|
||||
var lines = source.Replace("\r\n", "\n").Replace("\r", "\n").Split('\n');
|
||||
|
||||
int sectionStart = 0;
|
||||
int sectionEnd = lines.Length;
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
if (!ScriptParserHelper.IsSectionHeader(lines[i]))
|
||||
continue;
|
||||
sectionStart = i + 1;
|
||||
sectionEnd = lines.Length;
|
||||
for (int j = sectionStart; j < lines.Length; j++)
|
||||
{
|
||||
if (ScriptParserHelper.IsSectionHeader(lines[j]))
|
||||
{
|
||||
sectionEnd = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
var lines = ScriptParserHelper.SplitLines(source);
|
||||
ScriptParserHelper.TryFindSection(lines, out int sectionStart, out int sectionEnd);
|
||||
|
||||
for (int i = sectionStart; i < sectionEnd; i++)
|
||||
layout.ParseLine(lines[i]);
|
||||
@@ -72,21 +54,8 @@ namespace LuaScript.Compat
|
||||
|
||||
private void ParseLine(string line)
|
||||
{
|
||||
int i = ScriptParserHelper.SkipSpaces(line, 0);
|
||||
if (i + 1 >= line.Length || line[i] != '-' || line[i + 1] != '-')
|
||||
if (!ScriptParserHelper.TryParseDirective(line, out string name, out string content))
|
||||
return;
|
||||
i += 2;
|
||||
if (i < line.Length && line[i] == '!')
|
||||
return;
|
||||
|
||||
int nameStart = i;
|
||||
while (i < line.Length && ScriptParserHelper.IsNameChar(line[i]))
|
||||
i++;
|
||||
if (i >= line.Length || line[i] != ':')
|
||||
return;
|
||||
|
||||
string name = line.Substring(nameStart, i - nameStart);
|
||||
string content = line.Substring(i + 1);
|
||||
|
||||
if (name.StartsWith("track", StringComparison.OrdinalIgnoreCase) &&
|
||||
TryGetIndex(name, 5, MaxTracks, out int trackIndex))
|
||||
@@ -20,30 +20,8 @@ namespace LuaScript.Compat
|
||||
if (string.IsNullOrEmpty(source))
|
||||
return (source, []);
|
||||
|
||||
var lines = source.Replace("\r\n", "\n").Replace("\r", "\n").Split('\n');
|
||||
|
||||
int sectionStart = 0;
|
||||
int sectionEnd = lines.Length;
|
||||
bool hasSection = false;
|
||||
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
if (!ScriptParserHelper.IsSectionHeader(lines[i]))
|
||||
continue;
|
||||
|
||||
hasSection = true;
|
||||
sectionStart = i + 1;
|
||||
sectionEnd = lines.Length;
|
||||
for (int j = sectionStart; j < lines.Length; j++)
|
||||
{
|
||||
if (ScriptParserHelper.IsSectionHeader(lines[j]))
|
||||
{
|
||||
sectionEnd = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
var lines = ScriptParserHelper.SplitLines(source);
|
||||
bool hasSection = ScriptParserHelper.TryFindSection(lines, out int sectionStart, out int sectionEnd);
|
||||
|
||||
var prelude = new List<string>();
|
||||
for (int i = sectionStart; i < sectionEnd; i++)
|
||||
@@ -72,21 +50,8 @@ namespace LuaScript.Compat
|
||||
|
||||
private static void AppendDeclarations(string line, List<string> prelude)
|
||||
{
|
||||
int i = ScriptParserHelper.SkipSpaces(line, 0);
|
||||
if (i + 1 >= line.Length || line[i] != '-' || line[i + 1] != '-')
|
||||
if (!ScriptParserHelper.TryParseDirective(line, out string name, out string content))
|
||||
return;
|
||||
i += 2;
|
||||
if (i < line.Length && line[i] == '!')
|
||||
return;
|
||||
|
||||
int nameStart = i;
|
||||
while (i < line.Length && ScriptParserHelper.IsNameChar(line[i]))
|
||||
i++;
|
||||
if (i >= line.Length || line[i] != ':')
|
||||
return;
|
||||
|
||||
string name = line.Substring(nameStart, i - nameStart);
|
||||
string content = line.Substring(i + 1);
|
||||
|
||||
switch (Classify(name))
|
||||
{
|
||||
差分なしでファイル名を変更。
@@ -0,0 +1,69 @@
|
||||
namespace LuaScript.Compat
|
||||
{
|
||||
internal static class ScriptParserHelper
|
||||
{
|
||||
public static bool IsSectionHeader(string line)
|
||||
{
|
||||
int i = SkipSpaces(line, 0);
|
||||
return i < line.Length && line[i] == '@';
|
||||
}
|
||||
|
||||
public static int SkipSpaces(string text, int index)
|
||||
{
|
||||
while (index < text.Length && (text[index] == ' ' || text[index] == '\t'))
|
||||
index++;
|
||||
return index;
|
||||
}
|
||||
|
||||
public static bool IsNameChar(char c) =>
|
||||
(c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9');
|
||||
|
||||
public static string[] SplitLines(string source) =>
|
||||
source.Replace("\r\n", "\n").Replace("\r", "\n").Split('\n');
|
||||
|
||||
public static bool TryFindSection(string[] lines, out int start, out int end)
|
||||
{
|
||||
start = 0;
|
||||
end = lines.Length;
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
if (!IsSectionHeader(lines[i]))
|
||||
continue;
|
||||
start = i + 1;
|
||||
end = lines.Length;
|
||||
for (int j = start; j < lines.Length; j++)
|
||||
{
|
||||
if (IsSectionHeader(lines[j]))
|
||||
{
|
||||
end = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool TryParseDirective(string line, out string name, out string content)
|
||||
{
|
||||
name = string.Empty;
|
||||
content = string.Empty;
|
||||
int i = SkipSpaces(line, 0);
|
||||
if (i + 1 >= line.Length || line[i] != '-' || line[i + 1] != '-')
|
||||
return false;
|
||||
i += 2;
|
||||
if (i < line.Length && line[i] == '!')
|
||||
return false;
|
||||
|
||||
int nameStart = i;
|
||||
while (i < line.Length && IsNameChar(line[i]))
|
||||
i++;
|
||||
if (i >= line.Length || line[i] != ':')
|
||||
return false;
|
||||
|
||||
name = line.Substring(nameStart, i - nameStart);
|
||||
content = line.Substring(i + 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System.Collections;
|
||||
|
||||
namespace LuaScript.Generator
|
||||
{
|
||||
internal readonly struct EquatableArray<T>(T[] items) : IEquatable<EquatableArray<T>>, IReadOnlyList<T>
|
||||
where T : IEquatable<T>
|
||||
{
|
||||
private readonly T[] _items = items;
|
||||
|
||||
public static readonly EquatableArray<T> Empty = new([]);
|
||||
|
||||
public int Count => _items?.Length ?? 0;
|
||||
|
||||
public T this[int index] => _items[index];
|
||||
|
||||
public bool Equals(EquatableArray<T> other)
|
||||
{
|
||||
var a = _items ?? [];
|
||||
var b = other._items ?? [];
|
||||
if (a.Length != b.Length)
|
||||
return false;
|
||||
for (int i = 0; i < a.Length; i++)
|
||||
{
|
||||
if (!a[i].Equals(b[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj) => obj is EquatableArray<T> other && Equals(other);
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
var items = _items ?? [];
|
||||
int hash = 17;
|
||||
foreach (var item in items)
|
||||
hash = hash * 31 + (item?.GetHashCode() ?? 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator() => ((IEnumerable<T>)(_items ?? [])).GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
internal static class IsExternalInit;
|
||||
}
|
||||
@@ -0,0 +1,486 @@
|
||||
using System.Text;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
|
||||
namespace LuaScript.Generator
|
||||
{
|
||||
internal enum LuaParameterKind
|
||||
{
|
||||
ExecutionContext,
|
||||
Arguments,
|
||||
DynValue,
|
||||
Double,
|
||||
Int,
|
||||
Bool,
|
||||
}
|
||||
|
||||
internal enum LuaReturnKind
|
||||
{
|
||||
DynValue,
|
||||
Double,
|
||||
Void,
|
||||
}
|
||||
|
||||
internal sealed record LuaParameterModel(string Name, LuaParameterKind Kind, string DefaultLiteral);
|
||||
|
||||
internal sealed record LuaFunctionModel(
|
||||
string LuaName,
|
||||
string MethodName,
|
||||
LuaReturnKind ReturnKind,
|
||||
EquatableArray<LuaParameterModel> Parameters);
|
||||
|
||||
internal sealed record LuaConstantModel(string LuaName, string MemberName);
|
||||
|
||||
internal enum LuaUpdateKind
|
||||
{
|
||||
Direct,
|
||||
OptionalValue,
|
||||
OptionalReference,
|
||||
}
|
||||
|
||||
internal sealed record LuaUpdateModel(string LuaName, string MethodName, LuaUpdateKind Kind);
|
||||
|
||||
internal sealed record LuaCatalogEntry(
|
||||
string Table,
|
||||
string Name,
|
||||
bool IsFunction,
|
||||
EquatableArray<string> Parameters);
|
||||
|
||||
internal sealed record LuaTypePart(string Name, bool IsStatic);
|
||||
|
||||
internal sealed record LuaTableModel(
|
||||
string Namespace,
|
||||
EquatableArray<LuaTypePart> TypeChain,
|
||||
string TableName,
|
||||
string ContextType,
|
||||
EquatableArray<LuaFunctionModel> Functions,
|
||||
EquatableArray<LuaConstantModel> Constants,
|
||||
EquatableArray<LuaUpdateModel> Updates,
|
||||
EquatableArray<LuaCatalogEntry> Entries);
|
||||
|
||||
[Generator]
|
||||
public sealed class LuaApiGenerator : IIncrementalGenerator
|
||||
{
|
||||
private const string TableAttributeName = "LuaScript.Api.LuaTableAttribute";
|
||||
private const string FunctionAttributeName = "LuaScript.Api.LuaFunctionAttribute";
|
||||
private const string ConstantAttributeName = "LuaScript.Api.LuaConstantAttribute";
|
||||
private const string VariableAttributeName = "LuaScript.Api.LuaVariableAttribute";
|
||||
private const string BuiltinAttributeName = "LuaScript.Api.LuaBuiltinAttribute";
|
||||
|
||||
public void Initialize(IncrementalGeneratorInitializationContext context)
|
||||
{
|
||||
var tables = context.SyntaxProvider
|
||||
.ForAttributeWithMetadataName(
|
||||
TableAttributeName,
|
||||
static (node, _) => node is ClassDeclarationSyntax,
|
||||
static (ctx, _) => CreateModel(ctx))
|
||||
.Where(static model => model is not null)
|
||||
.Select(static (model, _) => model!);
|
||||
|
||||
var assemblyEntries = context.CompilationProvider
|
||||
.Select(static (compilation, _) => CollectAssemblyEntries(compilation));
|
||||
|
||||
context.RegisterSourceOutput(tables, static (ctx, model) =>
|
||||
{
|
||||
if (model.Functions.Count == 0 && model.Constants.Count == 0 && model.Updates.Count == 0)
|
||||
return;
|
||||
ctx.AddSource(RegistrationHintName(model), SourceText.From(EmitRegistration(model), Encoding.UTF8));
|
||||
});
|
||||
|
||||
var catalog = tables.Collect().Combine(assemblyEntries);
|
||||
context.RegisterSourceOutput(catalog, static (ctx, source) =>
|
||||
{
|
||||
var (models, extra) = source;
|
||||
var entries = models
|
||||
.OrderBy(static m => m.Namespace, StringComparer.Ordinal)
|
||||
.ThenBy(static m => string.Join("+", m.TypeChain.Select(static p => p.Name)), StringComparer.Ordinal)
|
||||
.SelectMany(static m => m.Entries)
|
||||
.Concat(extra)
|
||||
.ToArray();
|
||||
if (entries.Length == 0)
|
||||
return;
|
||||
ctx.AddSource("LuaApiCatalog.g.cs", SourceText.From(EmitCatalog(entries), Encoding.UTF8));
|
||||
});
|
||||
}
|
||||
|
||||
private static LuaTableModel? CreateModel(GeneratorAttributeSyntaxContext context)
|
||||
{
|
||||
if (context.TargetSymbol is not INamedTypeSymbol symbol)
|
||||
return null;
|
||||
|
||||
var tableArguments = context.Attributes[0].ConstructorArguments;
|
||||
string tableName = tableArguments.Length > 0 && tableArguments[0].Value is string name ? name : string.Empty;
|
||||
|
||||
var chain = new List<LuaTypePart>();
|
||||
for (var type = symbol; type is not null; type = type.ContainingType)
|
||||
chain.Insert(0, new LuaTypePart(type.Name, type.IsStatic));
|
||||
|
||||
var entries = new List<(int Position, LuaCatalogEntry Entry)>();
|
||||
foreach (var attribute in symbol.GetAttributes())
|
||||
{
|
||||
string? attributeName = attribute.AttributeClass?.ToDisplayString();
|
||||
if (attributeName is not (VariableAttributeName or BuiltinAttributeName or FunctionAttributeName))
|
||||
continue;
|
||||
var entry = CreateAttributeEntry(attribute, tableName);
|
||||
if (entry is null)
|
||||
continue;
|
||||
int position = attribute.ApplicationSyntaxReference?.Span.Start ?? 0;
|
||||
entries.Add((position, entry));
|
||||
}
|
||||
var classEntries = entries.OrderBy(static e => e.Position).Select(static e => e.Entry).ToList();
|
||||
|
||||
var functions = new List<(int Position, LuaFunctionModel Function, LuaCatalogEntry Entry)>();
|
||||
var constants = new List<(int Position, LuaConstantModel Constant, LuaCatalogEntry Entry)>();
|
||||
var updates = new List<(int Position, LuaUpdateModel Update, LuaCatalogEntry? Entry)>();
|
||||
string contextType = string.Empty;
|
||||
foreach (var member in symbol.GetMembers())
|
||||
{
|
||||
int position = member.DeclaringSyntaxReferences.Length > 0
|
||||
? member.DeclaringSyntaxReferences[0].Span.Start
|
||||
: 0;
|
||||
|
||||
if (member is IMethodSymbol method)
|
||||
{
|
||||
var functionAttribute = FindAttribute(method, FunctionAttributeName);
|
||||
if (functionAttribute is not null)
|
||||
{
|
||||
var function = CreateFunctionModel(method, functionAttribute, out var catalogParameters);
|
||||
if (function is null)
|
||||
continue;
|
||||
functions.Add((position, function, new LuaCatalogEntry(tableName, function.LuaName, true, catalogParameters)));
|
||||
continue;
|
||||
}
|
||||
|
||||
var variableAttribute = FindAttribute(method, VariableAttributeName);
|
||||
if (variableAttribute is not null)
|
||||
{
|
||||
var update = CreateUpdateModel(method, variableAttribute, tableName, ref contextType, out var entry);
|
||||
if (update is not null)
|
||||
updates.Add((position, update, entry));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (member is IFieldSymbol or IPropertySymbol)
|
||||
{
|
||||
var attribute = FindAttribute(member, ConstantAttributeName);
|
||||
if (attribute is null)
|
||||
continue;
|
||||
if (attribute.ConstructorArguments.Length == 0 || attribute.ConstructorArguments[0].Value is not string constantName)
|
||||
continue;
|
||||
constants.Add((
|
||||
position,
|
||||
new LuaConstantModel(constantName, member.Name),
|
||||
new LuaCatalogEntry(tableName, constantName, false, EquatableArray<string>.Empty)));
|
||||
}
|
||||
}
|
||||
|
||||
var orderedMembers = functions
|
||||
.Select(static f => (Position: f.Position, Entry: f.Entry))
|
||||
.Concat(constants.Select(static c => (Position: c.Position, Entry: c.Entry)))
|
||||
.Concat(updates.Where(static u => u.Entry is not null).Select(static u => (Position: u.Position, Entry: u.Entry!)))
|
||||
.OrderBy(static e => e.Position)
|
||||
.Select(static e => e.Entry);
|
||||
|
||||
return new LuaTableModel(
|
||||
symbol.ContainingNamespace.ToDisplayString(),
|
||||
new EquatableArray<LuaTypePart>([.. chain]),
|
||||
tableName,
|
||||
contextType,
|
||||
new EquatableArray<LuaFunctionModel>([.. functions.OrderBy(static f => f.Position).Select(static f => f.Function)]),
|
||||
new EquatableArray<LuaConstantModel>([.. constants.OrderBy(static c => c.Position).Select(static c => c.Constant)]),
|
||||
new EquatableArray<LuaUpdateModel>([.. updates.OrderBy(static u => u.Position).Select(static u => u.Update)]),
|
||||
new EquatableArray<LuaCatalogEntry>([.. classEntries, .. orderedMembers]));
|
||||
}
|
||||
|
||||
private static AttributeData? FindAttribute(ISymbol symbol, string attributeName)
|
||||
{
|
||||
foreach (var attribute in symbol.GetAttributes())
|
||||
{
|
||||
if (attribute.AttributeClass?.ToDisplayString() == attributeName)
|
||||
return attribute;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static LuaCatalogEntry? CreateAttributeEntry(AttributeData attribute, string defaultTable)
|
||||
{
|
||||
if (attribute.ConstructorArguments.Length == 0 || attribute.ConstructorArguments[0].Value is not string name)
|
||||
return null;
|
||||
|
||||
string table = defaultTable;
|
||||
foreach (var argument in attribute.NamedArguments)
|
||||
{
|
||||
if (argument.Key == "Table" && argument.Value.Value is string overridden)
|
||||
table = overridden;
|
||||
}
|
||||
|
||||
bool isFunction = attribute.AttributeClass?.ToDisplayString() is (BuiltinAttributeName or FunctionAttributeName);
|
||||
var parameters = isFunction && attribute.ConstructorArguments.Length > 1
|
||||
? ExtractStringArray(attribute.ConstructorArguments[1])
|
||||
: EquatableArray<string>.Empty;
|
||||
|
||||
return new LuaCatalogEntry(table, name, isFunction, parameters);
|
||||
}
|
||||
|
||||
private static EquatableArray<string> ExtractStringArray(TypedConstant constant)
|
||||
{
|
||||
if (constant.Kind != TypedConstantKind.Array)
|
||||
return EquatableArray<string>.Empty;
|
||||
return new EquatableArray<string>([.. constant.Values.Select(static v => v.Value as string ?? string.Empty)]);
|
||||
}
|
||||
|
||||
private static LuaFunctionModel? CreateFunctionModel(IMethodSymbol method, AttributeData attribute, out EquatableArray<string> catalogParameters)
|
||||
{
|
||||
catalogParameters = EquatableArray<string>.Empty;
|
||||
if (attribute.ConstructorArguments.Length == 0 || attribute.ConstructorArguments[0].Value is not string luaName)
|
||||
return null;
|
||||
|
||||
LuaReturnKind returnKind;
|
||||
if (method.ReturnsVoid)
|
||||
returnKind = LuaReturnKind.Void;
|
||||
else if (method.ReturnType.ToDisplayString() == "MoonSharp.Interpreter.DynValue")
|
||||
returnKind = LuaReturnKind.DynValue;
|
||||
else if (method.ReturnType.SpecialType == SpecialType.System_Double)
|
||||
returnKind = LuaReturnKind.Double;
|
||||
else
|
||||
return null;
|
||||
|
||||
var parameters = new List<LuaParameterModel>();
|
||||
foreach (var parameter in method.Parameters)
|
||||
{
|
||||
LuaParameterKind kind;
|
||||
string defaultLiteral = string.Empty;
|
||||
switch (parameter.Type.ToDisplayString())
|
||||
{
|
||||
case "MoonSharp.Interpreter.ScriptExecutionContext":
|
||||
kind = LuaParameterKind.ExecutionContext;
|
||||
break;
|
||||
case "MoonSharp.Interpreter.CallbackArguments":
|
||||
kind = LuaParameterKind.Arguments;
|
||||
break;
|
||||
case "MoonSharp.Interpreter.DynValue":
|
||||
kind = LuaParameterKind.DynValue;
|
||||
break;
|
||||
case "double":
|
||||
kind = LuaParameterKind.Double;
|
||||
defaultLiteral = FormatDouble(parameter.HasExplicitDefaultValue ? (double)parameter.ExplicitDefaultValue! : 0d);
|
||||
break;
|
||||
case "int":
|
||||
kind = LuaParameterKind.Int;
|
||||
defaultLiteral = FormatDouble(parameter.HasExplicitDefaultValue ? (int)parameter.ExplicitDefaultValue! : 0);
|
||||
break;
|
||||
case "bool":
|
||||
kind = LuaParameterKind.Bool;
|
||||
defaultLiteral = parameter.HasExplicitDefaultValue && (bool)parameter.ExplicitDefaultValue! ? "true" : "false";
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
parameters.Add(new LuaParameterModel(parameter.Name, kind, defaultLiteral));
|
||||
}
|
||||
|
||||
var explicitParameters = attribute.ConstructorArguments.Length > 1
|
||||
? ExtractStringArray(attribute.ConstructorArguments[1])
|
||||
: EquatableArray<string>.Empty;
|
||||
catalogParameters = explicitParameters.Count > 0
|
||||
? explicitParameters
|
||||
: new EquatableArray<string>([.. parameters
|
||||
.Where(static p => p.Kind is not (LuaParameterKind.ExecutionContext or LuaParameterKind.Arguments))
|
||||
.Select(static p => p.Name)]);
|
||||
|
||||
return new LuaFunctionModel(luaName, method.Name, returnKind, new EquatableArray<LuaParameterModel>([.. parameters]));
|
||||
}
|
||||
|
||||
private static LuaUpdateModel? CreateUpdateModel(IMethodSymbol method, AttributeData attribute, string tableName, ref string contextType, out LuaCatalogEntry? entry)
|
||||
{
|
||||
entry = null;
|
||||
if (attribute.ConstructorArguments.Length == 0 || attribute.ConstructorArguments[0].Value is not string luaName)
|
||||
return null;
|
||||
if (method.Parameters.Length != 1)
|
||||
return null;
|
||||
|
||||
string parameterType = method.Parameters[0].Type.ToDisplayString();
|
||||
if (contextType.Length == 0)
|
||||
contextType = parameterType;
|
||||
else if (contextType != parameterType)
|
||||
return null;
|
||||
|
||||
var returnType = method.ReturnType;
|
||||
LuaUpdateKind kind;
|
||||
if (returnType.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T)
|
||||
kind = LuaUpdateKind.OptionalValue;
|
||||
else if (returnType.IsReferenceType)
|
||||
kind = LuaUpdateKind.OptionalReference;
|
||||
else
|
||||
kind = LuaUpdateKind.Direct;
|
||||
|
||||
bool inCatalog = true;
|
||||
foreach (var argument in attribute.NamedArguments)
|
||||
{
|
||||
if (argument.Key == "InCatalog" && argument.Value.Value is bool value)
|
||||
inCatalog = value;
|
||||
}
|
||||
|
||||
if (inCatalog)
|
||||
entry = new LuaCatalogEntry(tableName, luaName, false, EquatableArray<string>.Empty);
|
||||
return new LuaUpdateModel(luaName, method.Name, kind);
|
||||
}
|
||||
|
||||
private static string FormatDouble(double value) =>
|
||||
value.ToString("R", System.Globalization.CultureInfo.InvariantCulture) + "d";
|
||||
|
||||
private static string RegistrationHintName(LuaTableModel model)
|
||||
{
|
||||
var chain = string.Join(".", model.TypeChain.Select(static p => p.Name));
|
||||
return $"{model.Namespace}.{chain}.LuaRegistration.g.cs";
|
||||
}
|
||||
|
||||
private static string EmitRegistration(LuaTableModel model)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
builder.AppendLine("#nullable enable");
|
||||
builder.AppendLine($"namespace {model.Namespace}");
|
||||
builder.AppendLine("{");
|
||||
|
||||
string indent = " ";
|
||||
foreach (var part in model.TypeChain)
|
||||
{
|
||||
builder.AppendLine($"{indent}{(part.IsStatic ? "static partial class " : "partial class ")}{part.Name}");
|
||||
builder.AppendLine($"{indent}{{");
|
||||
indent += " ";
|
||||
}
|
||||
|
||||
bool isStatic = model.TypeChain[model.TypeChain.Count - 1].IsStatic;
|
||||
string body = indent + " ";
|
||||
|
||||
if (model.Constants.Count > 0 || model.Functions.Count > 0)
|
||||
{
|
||||
builder.AppendLine($"{indent}internal {(isStatic ? "static " : "")}void RegisterLuaMembers(global::MoonSharp.Interpreter.Table table)");
|
||||
builder.AppendLine($"{indent}{{");
|
||||
|
||||
foreach (var constant in model.Constants)
|
||||
builder.AppendLine($"{body}table[\"{constant.LuaName}\"] = {constant.MemberName};");
|
||||
|
||||
foreach (var function in model.Functions)
|
||||
{
|
||||
string call = $"{function.MethodName}({EmitArguments(function.Parameters)})";
|
||||
string lambda = function.ReturnKind switch
|
||||
{
|
||||
LuaReturnKind.DynValue => $"(execCtx, args) => {call}",
|
||||
LuaReturnKind.Double => $"(execCtx, args) => global::MoonSharp.Interpreter.DynValue.NewNumber({call})",
|
||||
_ => $"(execCtx, args) => {{ {call}; return global::MoonSharp.Interpreter.DynValue.Void; }}",
|
||||
};
|
||||
builder.AppendLine($"{body}table[\"{function.LuaName}\"] = global::MoonSharp.Interpreter.DynValue.NewCallback({lambda});");
|
||||
}
|
||||
|
||||
builder.AppendLine($"{indent}}}");
|
||||
}
|
||||
|
||||
if (model.Updates.Count > 0)
|
||||
{
|
||||
builder.AppendLine($"{indent}internal {(isStatic ? "static " : "")}void UpdateLuaMembers(global::MoonSharp.Interpreter.Table table, global::{model.ContextType} context)");
|
||||
builder.AppendLine($"{indent}{{");
|
||||
foreach (var update in model.Updates)
|
||||
{
|
||||
switch (update.Kind)
|
||||
{
|
||||
case LuaUpdateKind.OptionalValue:
|
||||
builder.AppendLine($"{body}{{ var value = {update.MethodName}(context); if (value.HasValue) table[\"{update.LuaName}\"] = value.Value; }}");
|
||||
break;
|
||||
case LuaUpdateKind.OptionalReference:
|
||||
builder.AppendLine($"{body}{{ var value = {update.MethodName}(context); if (value is not null) table[\"{update.LuaName}\"] = value; }}");
|
||||
break;
|
||||
default:
|
||||
builder.AppendLine($"{body}table[\"{update.LuaName}\"] = {update.MethodName}(context);");
|
||||
break;
|
||||
}
|
||||
}
|
||||
builder.AppendLine($"{indent}}}");
|
||||
}
|
||||
|
||||
for (int i = model.TypeChain.Count - 1; i >= 0; i--)
|
||||
{
|
||||
indent = new string(' ', 4 * (i + 1));
|
||||
builder.AppendLine($"{indent}}}");
|
||||
}
|
||||
builder.AppendLine("}");
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
private static string EmitArguments(EquatableArray<LuaParameterModel> parameters)
|
||||
{
|
||||
var rendered = new List<string>();
|
||||
int position = 0;
|
||||
foreach (var parameter in parameters)
|
||||
{
|
||||
if (parameter.Kind == LuaParameterKind.ExecutionContext)
|
||||
{
|
||||
rendered.Add("execCtx");
|
||||
continue;
|
||||
}
|
||||
if (parameter.Kind == LuaParameterKind.Arguments)
|
||||
{
|
||||
rendered.Add("args");
|
||||
continue;
|
||||
}
|
||||
rendered.Add(parameter.Kind switch
|
||||
{
|
||||
LuaParameterKind.DynValue => $"args.Count > {position} ? args[{position}] : global::MoonSharp.Interpreter.DynValue.Nil",
|
||||
LuaParameterKind.Double => $"args.Count > {position} ? args[{position}].CastToNumber() ?? {parameter.DefaultLiteral} : {parameter.DefaultLiteral}",
|
||||
LuaParameterKind.Int => $"(int)(args.Count > {position} ? args[{position}].CastToNumber() ?? {parameter.DefaultLiteral} : {parameter.DefaultLiteral})",
|
||||
_ => $"args.Count > {position} ? args[{position}].CastToBool() : {parameter.DefaultLiteral}",
|
||||
});
|
||||
position++;
|
||||
}
|
||||
return string.Join(", ", rendered);
|
||||
}
|
||||
|
||||
private static string EmitCatalog(LuaCatalogEntry[] entries)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
builder.AppendLine("#nullable enable");
|
||||
builder.AppendLine("namespace LuaScript.Generated");
|
||||
builder.AppendLine("{");
|
||||
builder.AppendLine(" internal static class LuaApiModuleInitializer");
|
||||
builder.AppendLine(" {");
|
||||
builder.AppendLine(" [global::System.Runtime.CompilerServices.ModuleInitializer]");
|
||||
builder.AppendLine(" internal static void Initialize()");
|
||||
builder.AppendLine(" {");
|
||||
builder.AppendLine(" global::LuaScript.Api.LuaApiCatalog.Register(new global::LuaScript.Api.LuaApiMember[]");
|
||||
builder.AppendLine(" {");
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
string kind = entry.IsFunction
|
||||
? "global::LuaScript.Api.LuaApiMemberKind.Function"
|
||||
: "global::LuaScript.Api.LuaApiMemberKind.Variable";
|
||||
string parameters = entry.Parameters.Count == 0
|
||||
? "global::System.Array.Empty<string>()"
|
||||
: $"new string[] {{ {string.Join(", ", entry.Parameters.Select(static p => $"\"{p}\""))} }}";
|
||||
builder.AppendLine($" new(\"{entry.Table}\", \"{entry.Name}\", {kind}, {parameters}),");
|
||||
}
|
||||
builder.AppendLine(" });");
|
||||
builder.AppendLine(" }");
|
||||
builder.AppendLine(" }");
|
||||
builder.AppendLine("}");
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
private static IReadOnlyList<LuaCatalogEntry> CollectAssemblyEntries(Compilation compilation)
|
||||
{
|
||||
var entries = new List<(int Position, LuaCatalogEntry Entry)>();
|
||||
foreach (var attribute in compilation.Assembly.GetAttributes())
|
||||
{
|
||||
string? attributeName = attribute.AttributeClass?.ToDisplayString();
|
||||
if (attributeName is not (VariableAttributeName or BuiltinAttributeName or FunctionAttributeName))
|
||||
continue;
|
||||
var entry = CreateAttributeEntry(attribute, string.Empty);
|
||||
if (entry is null)
|
||||
continue;
|
||||
entries.Add((attribute.ApplicationSyntaxReference?.Span.Start ?? 0, entry));
|
||||
}
|
||||
return [.. entries.OrderBy(static e => e.Position).Select(static e => e.Entry)];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>1.13.4</Version>
|
||||
<IsRoslynComponent>true</IsRoslynComponent>
|
||||
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="5.3.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.3.0" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
差分なしでファイル名を変更。
差分なしでファイル名を変更。
+1
-7
@@ -9,12 +9,6 @@ namespace LuaScript.Engine.Kernel
|
||||
|
||||
public const int ConstantFloatCount = ConstantVectorCount * 4;
|
||||
|
||||
private static readonly string[] Intrinsics =
|
||||
[
|
||||
"abs", "floor", "ceil", "sqrt", "sin", "cos", "tan", "asin", "acos",
|
||||
"atan", "atan2", "exp", "log", "pow", "min", "max", "fmod",
|
||||
];
|
||||
|
||||
public static string Emit(KernelProgram program)
|
||||
{
|
||||
var builder = new StringBuilder(1024);
|
||||
@@ -153,7 +147,7 @@ namespace LuaScript.Engine.Kernel
|
||||
|
||||
private static void EmitCall(StringBuilder builder, KCall call)
|
||||
{
|
||||
builder.Append(Intrinsics[(int)call.Func]).Append('(');
|
||||
builder.Append(KFunctions.Intrinsic(call.Func)).Append('(');
|
||||
for (int i = 0; i < call.Arguments.Count; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
+1
-24
@@ -5,29 +5,6 @@ namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed class KernelExtractor
|
||||
{
|
||||
private readonly record struct FuncSpec(KFunc Func, int MinArgs, int MaxArgs);
|
||||
|
||||
private static readonly Dictionary<string, FuncSpec> MathFunctions = new(StringComparer.Ordinal)
|
||||
{
|
||||
["abs"] = new(KFunc.Abs, 1, 1),
|
||||
["floor"] = new(KFunc.Floor, 1, 1),
|
||||
["ceil"] = new(KFunc.Ceil, 1, 1),
|
||||
["sqrt"] = new(KFunc.Sqrt, 1, 1),
|
||||
["sin"] = new(KFunc.Sin, 1, 1),
|
||||
["cos"] = new(KFunc.Cos, 1, 1),
|
||||
["tan"] = new(KFunc.Tan, 1, 1),
|
||||
["asin"] = new(KFunc.Asin, 1, 1),
|
||||
["acos"] = new(KFunc.Acos, 1, 1),
|
||||
["atan"] = new(KFunc.Atan, 1, 1),
|
||||
["atan2"] = new(KFunc.Atan2, 2, 2),
|
||||
["exp"] = new(KFunc.Exp, 1, 1),
|
||||
["log"] = new(KFunc.Log, 1, 1),
|
||||
["pow"] = new(KFunc.Pow, 2, 2),
|
||||
["fmod"] = new(KFunc.Fmod, 2, 2),
|
||||
["min"] = new(KFunc.Min, 2, int.MaxValue),
|
||||
["max"] = new(KFunc.Max, 2, int.MaxValue),
|
||||
};
|
||||
|
||||
private readonly List<KExpr> _bindings = [];
|
||||
private readonly Dictionary<string, int> _scope = new(StringComparer.Ordinal);
|
||||
private readonly SortedSet<KernelUniform> _uniforms = [];
|
||||
@@ -372,7 +349,7 @@ namespace LuaScript.Engine.Kernel
|
||||
private KExpr LowerCall(CallExpr call)
|
||||
{
|
||||
if (call.Target is not MemberExpr { Target: NameExpr { Name: "math" }, Name: var function } ||
|
||||
!MathFunctions.TryGetValue(function, out var spec))
|
||||
!KFunctions.TryResolve(function, out var spec))
|
||||
throw new KernelUnsupportedException("Unsupported function call in pixel kernel.");
|
||||
|
||||
int count = call.Arguments.Count;
|
||||
差分なしでファイル名を変更。
差分なしでファイル名を変更。
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record KArith(KArithOp Op, KExpr Left, KExpr Right) : KExpr;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal enum KArithOp
|
||||
{
|
||||
Add,
|
||||
Subtract,
|
||||
Multiply,
|
||||
Divide,
|
||||
Modulo,
|
||||
Power,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal enum KAxis
|
||||
{
|
||||
X,
|
||||
Y,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal abstract record KBool;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record KBoolConst(bool Value) : KBool;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record KCall(KFunc Func, IReadOnlyList<KExpr> Arguments) : KExpr;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal enum KChannel
|
||||
{
|
||||
R,
|
||||
G,
|
||||
B,
|
||||
A,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record KCompare(KCompareOp Op, KExpr Left, KExpr Right) : KBool;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal enum KCompareOp
|
||||
{
|
||||
Less,
|
||||
Greater,
|
||||
LessEqual,
|
||||
GreaterEqual,
|
||||
Equal,
|
||||
NotEqual,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record KConst(double Value) : KExpr;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record KCoord(KAxis Axis) : KExpr;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal abstract record KExpr;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal enum KFunc
|
||||
{
|
||||
Abs,
|
||||
Floor,
|
||||
Ceil,
|
||||
Sqrt,
|
||||
Sin,
|
||||
Cos,
|
||||
Tan,
|
||||
Asin,
|
||||
Acos,
|
||||
Atan,
|
||||
Atan2,
|
||||
Exp,
|
||||
Log,
|
||||
Pow,
|
||||
Min,
|
||||
Max,
|
||||
Fmod,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal readonly record struct KFunctionInfo(KFunc Func, string Name, int MinArgs, int MaxArgs);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal static class KFunctions
|
||||
{
|
||||
private static readonly KFunctionInfo[] Catalog =
|
||||
[
|
||||
new(KFunc.Abs, "abs", 1, 1),
|
||||
new(KFunc.Floor, "floor", 1, 1),
|
||||
new(KFunc.Ceil, "ceil", 1, 1),
|
||||
new(KFunc.Sqrt, "sqrt", 1, 1),
|
||||
new(KFunc.Sin, "sin", 1, 1),
|
||||
new(KFunc.Cos, "cos", 1, 1),
|
||||
new(KFunc.Tan, "tan", 1, 1),
|
||||
new(KFunc.Asin, "asin", 1, 1),
|
||||
new(KFunc.Acos, "acos", 1, 1),
|
||||
new(KFunc.Atan, "atan", 1, 1),
|
||||
new(KFunc.Atan2, "atan2", 2, 2),
|
||||
new(KFunc.Exp, "exp", 1, 1),
|
||||
new(KFunc.Log, "log", 1, 1),
|
||||
new(KFunc.Pow, "pow", 2, 2),
|
||||
new(KFunc.Min, "min", 2, int.MaxValue),
|
||||
new(KFunc.Max, "max", 2, int.MaxValue),
|
||||
new(KFunc.Fmod, "fmod", 2, 2),
|
||||
];
|
||||
|
||||
private static readonly Dictionary<string, KFunctionInfo> ByName = BuildByName();
|
||||
private static readonly string[] Intrinsics = BuildIntrinsics();
|
||||
|
||||
public static bool TryResolve(string name, out KFunctionInfo info) => ByName.TryGetValue(name, out info);
|
||||
|
||||
public static string Intrinsic(KFunc func) => Intrinsics[(int)func];
|
||||
|
||||
private static Dictionary<string, KFunctionInfo> BuildByName()
|
||||
{
|
||||
var map = new Dictionary<string, KFunctionInfo>(Catalog.Length, StringComparer.Ordinal);
|
||||
foreach (var info in Catalog)
|
||||
map[info.Name] = info;
|
||||
return map;
|
||||
}
|
||||
|
||||
private static string[] BuildIntrinsics()
|
||||
{
|
||||
var names = new string[Enum.GetValues<KFunc>().Length];
|
||||
foreach (var info in Catalog)
|
||||
names[(int)info.Func] = info.Name;
|
||||
return names;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record KInput(KChannel Channel) : KExpr;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record KLocalRef(int Slot) : KExpr;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record KLogical(bool IsAnd, KBool Left, KBool Right) : KBool;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record KNegate(KExpr Operand) : KExpr;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record KNot(KBool Operand) : KBool;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record KSelect(KBool Condition, KExpr WhenTrue, KExpr WhenFalse) : KExpr;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record KUniformRef(KernelUniform Uniform) : KExpr;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record KernelProgram(
|
||||
IReadOnlyList<KExpr> Bindings,
|
||||
KExpr OutputR,
|
||||
KExpr OutputG,
|
||||
KExpr OutputB,
|
||||
KExpr OutputA,
|
||||
IReadOnlyList<KernelUniform> Uniforms);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal enum KernelUniform
|
||||
{
|
||||
Width,
|
||||
Height,
|
||||
HalfWidth,
|
||||
HalfHeight,
|
||||
CenterX,
|
||||
CenterY,
|
||||
CenterZ,
|
||||
Diagonal,
|
||||
X,
|
||||
Y,
|
||||
Z,
|
||||
Ox,
|
||||
Oy,
|
||||
Oz,
|
||||
Sx,
|
||||
Sy,
|
||||
Sz,
|
||||
Zoom,
|
||||
Aspect,
|
||||
Alpha,
|
||||
Rx,
|
||||
Ry,
|
||||
Rz,
|
||||
Rxr,
|
||||
Ryr,
|
||||
Rzr,
|
||||
Track0,
|
||||
Track1,
|
||||
Track2,
|
||||
Track3,
|
||||
Slider0,
|
||||
Slider1,
|
||||
Slider2,
|
||||
Slider3,
|
||||
Check0,
|
||||
Check1,
|
||||
Check2,
|
||||
Check3,
|
||||
Color,
|
||||
Time,
|
||||
Frame,
|
||||
TotalFrame,
|
||||
TotalTime,
|
||||
T,
|
||||
Framerate,
|
||||
Layer,
|
||||
Index,
|
||||
Num,
|
||||
SceneWidth,
|
||||
SceneHeight,
|
||||
SceneCenterX,
|
||||
SceneCenterY,
|
||||
TimelineFrame,
|
||||
TimelineTime,
|
||||
}
|
||||
}
|
||||
@@ -3,64 +3,6 @@ using System.Collections.Generic;
|
||||
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal enum KernelUniform
|
||||
{
|
||||
Width,
|
||||
Height,
|
||||
HalfWidth,
|
||||
HalfHeight,
|
||||
CenterX,
|
||||
CenterY,
|
||||
CenterZ,
|
||||
Diagonal,
|
||||
X,
|
||||
Y,
|
||||
Z,
|
||||
Ox,
|
||||
Oy,
|
||||
Oz,
|
||||
Sx,
|
||||
Sy,
|
||||
Sz,
|
||||
Zoom,
|
||||
Aspect,
|
||||
Alpha,
|
||||
Rx,
|
||||
Ry,
|
||||
Rz,
|
||||
Rxr,
|
||||
Ryr,
|
||||
Rzr,
|
||||
Track0,
|
||||
Track1,
|
||||
Track2,
|
||||
Track3,
|
||||
Slider0,
|
||||
Slider1,
|
||||
Slider2,
|
||||
Slider3,
|
||||
Check0,
|
||||
Check1,
|
||||
Check2,
|
||||
Check3,
|
||||
Color,
|
||||
Time,
|
||||
Frame,
|
||||
TotalFrame,
|
||||
TotalTime,
|
||||
T,
|
||||
Framerate,
|
||||
Layer,
|
||||
Index,
|
||||
Num,
|
||||
SceneWidth,
|
||||
SceneHeight,
|
||||
SceneCenterX,
|
||||
SceneCenterY,
|
||||
TimelineFrame,
|
||||
TimelineTime,
|
||||
}
|
||||
|
||||
internal static class KernelUniforms
|
||||
{
|
||||
public static int Count { get; } = Enum.GetValues<KernelUniform>().Length;
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record AssignStmt(IReadOnlyList<LuaExpr> Targets, IReadOnlyList<LuaExpr> Values) : LuaStmt;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record BinaryExpr(string Operator, LuaExpr Left, LuaExpr Right) : LuaExpr;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record BoolExpr(bool Value) : LuaExpr;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record CallExpr(LuaExpr Target, IReadOnlyList<LuaExpr> Arguments) : LuaExpr;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record CallStmt(LuaExpr Call) : LuaStmt;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record IfClause(LuaExpr Condition, IReadOnlyList<LuaStmt> Body);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record IfStmt(IReadOnlyList<IfClause> Clauses, IReadOnlyList<LuaStmt>? ElseBody) : LuaStmt;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record IndexExpr(LuaExpr Target, LuaExpr Key) : LuaExpr;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record LocalStmt(IReadOnlyList<string> Names, IReadOnlyList<LuaExpr> Values) : LuaStmt;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal abstract record LuaExpr;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal abstract record LuaStmt;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record MemberExpr(LuaExpr Target, string Name) : LuaExpr;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record MethodCallExpr(LuaExpr Target, string Method, IReadOnlyList<LuaExpr> Arguments) : LuaExpr;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record NameExpr(string Name) : LuaExpr;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record NilExpr : LuaExpr;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record NumberExpr(double Value) : LuaExpr;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record NumericForStmt(
|
||||
string Variable,
|
||||
LuaExpr Start,
|
||||
LuaExpr Stop,
|
||||
LuaExpr? Step,
|
||||
IReadOnlyList<LuaStmt> Body) : LuaStmt;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record StringExpr(string Value) : LuaExpr;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal sealed record UnaryExpr(string Operator, LuaExpr Operand) : LuaExpr;
|
||||
}
|
||||
@@ -2,16 +2,6 @@ using System;
|
||||
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal enum LuaTokenKind
|
||||
{
|
||||
Name,
|
||||
Number,
|
||||
String,
|
||||
Keyword,
|
||||
Symbol,
|
||||
Eof,
|
||||
}
|
||||
|
||||
internal readonly struct LuaToken(LuaTokenKind kind, string text, double number)
|
||||
{
|
||||
public LuaTokenKind Kind { get; } = kind;
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace LuaScript.Engine.Kernel
|
||||
{
|
||||
internal enum LuaTokenKind
|
||||
{
|
||||
Name,
|
||||
Number,
|
||||
String,
|
||||
Keyword,
|
||||
Symbol,
|
||||
Eof,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>1.13.4</Version>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="LuaScript" />
|
||||
<InternalsVisibleTo Include="LuaScript.Compat" />
|
||||
<InternalsVisibleTo Include="LuaScript.Runtime" />
|
||||
<InternalsVisibleTo Include="LuaScript.Tests" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,48 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>1.13.4</Version>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="LuaScript" />
|
||||
<InternalsVisibleTo Include="LuaScript.Tests" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="SharpGen.Runtime">
|
||||
<HintPath>$(YMM4DirPath)SharpGen.Runtime.dll</HintPath>
|
||||
<Private>false</Private>
|
||||
</Reference>
|
||||
<Reference Include="SharpGen.Runtime.COM">
|
||||
<HintPath>$(YMM4DirPath)SharpGen.Runtime.COM.dll</HintPath>
|
||||
<Private>false</Private>
|
||||
</Reference>
|
||||
<Reference Include="Vortice.Direct2D1">
|
||||
<HintPath>$(YMM4DirPath)Vortice.Direct2D1.dll</HintPath>
|
||||
<Private>false</Private>
|
||||
</Reference>
|
||||
<Reference Include="Vortice.DirectX">
|
||||
<HintPath>$(YMM4DirPath)Vortice.DirectX.dll</HintPath>
|
||||
<Private>false</Private>
|
||||
</Reference>
|
||||
<Reference Include="Vortice.DXGI.dll">
|
||||
<HintPath>$(YMM4DirPath)Vortice.DXGI.dll</HintPath>
|
||||
<Private>false</Private>
|
||||
</Reference>
|
||||
<Reference Include="Vortice.Mathematics">
|
||||
<HintPath>$(YMM4DirPath)Vortice.Mathematics.dll</HintPath>
|
||||
<Private>false</Private>
|
||||
</Reference>
|
||||
<Reference Include="Vortice.MediaFoundation">
|
||||
<HintPath>$(YMM4DirPath)Vortice.MediaFoundation.dll</HintPath>
|
||||
<Private>false</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace LuaScript.Anchor
|
||||
{
|
||||
internal enum AnchorConnection
|
||||
{
|
||||
None,
|
||||
Line,
|
||||
Loop,
|
||||
Star,
|
||||
Arm,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Anchor
|
||||
{
|
||||
internal readonly record struct AnchorOptions(AnchorConnection Connection, bool Is3D);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace LuaScript.Anchor
|
||||
{
|
||||
internal readonly record struct AnchorRequestData(string Group, int Count, AnchorConnection Connection, bool Is3D);
|
||||
}
|
||||
@@ -1,22 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace LuaScript.Anchor
|
||||
{
|
||||
internal enum AnchorConnection
|
||||
{
|
||||
None,
|
||||
Line,
|
||||
Loop,
|
||||
Star,
|
||||
Arm,
|
||||
}
|
||||
|
||||
internal readonly record struct AnchorOptions(AnchorConnection Connection, bool Is3D);
|
||||
|
||||
internal readonly record struct AnchorRequestData(string Group, int Count, AnchorConnection Connection, bool Is3D);
|
||||
|
||||
internal static class AnchorSupport
|
||||
{
|
||||
public const int MaxAnchors = 32;
|
||||
差分なしでファイル名を変更。
@@ -0,0 +1,38 @@
|
||||
namespace LuaScript.Api
|
||||
{
|
||||
internal static class LuaApiCatalog
|
||||
{
|
||||
private static readonly object s_gate = new();
|
||||
private static readonly List<LuaApiMember> s_members = [];
|
||||
private static LuaApiMember[]? s_snapshot;
|
||||
private static int s_version;
|
||||
|
||||
internal static int Version
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (s_gate)
|
||||
return s_version;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Register(IReadOnlyList<LuaApiMember> members)
|
||||
{
|
||||
lock (s_gate)
|
||||
{
|
||||
s_members.AddRange(members);
|
||||
s_snapshot = null;
|
||||
s_version++;
|
||||
}
|
||||
}
|
||||
|
||||
internal static IReadOnlyList<LuaApiMember> Members
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (s_gate)
|
||||
return s_snapshot ??= [.. s_members];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace LuaScript.Api
|
||||
{
|
||||
internal sealed record LuaApiMember(
|
||||
string Table,
|
||||
string Name,
|
||||
LuaApiMemberKind Kind,
|
||||
IReadOnlyList<string> Parameters)
|
||||
{
|
||||
public string QualifiedName => Table.Length == 0 ? Name : $"{Table}.{Name}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace LuaScript.Api
|
||||
{
|
||||
internal enum LuaApiMemberKind
|
||||
{
|
||||
Function,
|
||||
Variable,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace LuaScript.Api
|
||||
{
|
||||
[LuaTable("")]
|
||||
[LuaBuiltin("type", "v")]
|
||||
[LuaBuiltin("tostring", "v")]
|
||||
[LuaBuiltin("tonumber", "e", "base")]
|
||||
[LuaBuiltin("select", "n", "...")]
|
||||
[LuaBuiltin("error", "message", "level")]
|
||||
[LuaBuiltin("assert", "v", "message")]
|
||||
[LuaBuiltin("print", "...")]
|
||||
[LuaBuiltin("ipairs", "t")]
|
||||
[LuaBuiltin("pairs", "t")]
|
||||
[LuaBuiltin("next", "table", "index")]
|
||||
[LuaBuiltin("unpack", "list", "i", "j")]
|
||||
[LuaBuiltin("setmetatable", "table", "metatable")]
|
||||
[LuaBuiltin("getmetatable", "object")]
|
||||
[LuaBuiltin("rawget", "table", "index")]
|
||||
[LuaBuiltin("rawset", "table", "index", "value")]
|
||||
[LuaBuiltin("rawequal", "v1", "v2")]
|
||||
[LuaBuiltin("rawlen", "v")]
|
||||
[LuaBuiltin("pcall", "f", "...")]
|
||||
[LuaBuiltin("xpcall", "f", "msgh", "...")]
|
||||
internal static class LuaBasicLibrary;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace LuaScript.Api
|
||||
{
|
||||
[LuaTable("bit32")]
|
||||
[LuaBuiltin("band", "...")]
|
||||
[LuaBuiltin("bor", "...")]
|
||||
[LuaBuiltin("bxor", "...")]
|
||||
[LuaBuiltin("bnot", "x")]
|
||||
[LuaBuiltin("lshift", "x", "disp")]
|
||||
[LuaBuiltin("rshift", "x", "disp")]
|
||||
[LuaBuiltin("arshift", "x", "disp")]
|
||||
[LuaBuiltin("extract", "n", "field", "width")]
|
||||
[LuaBuiltin("replace", "n", "v", "field", "width")]
|
||||
[LuaBuiltin("btest", "...")]
|
||||
[LuaBuiltin("countlz", "x")]
|
||||
[LuaBuiltin("countrz", "x")]
|
||||
internal static class LuaBit32Library;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace LuaScript.Api
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Assembly, Inherited = false, AllowMultiple = true)]
|
||||
internal sealed class LuaBuiltinAttribute(string name, params string[] parameters) : Attribute
|
||||
{
|
||||
public string Name { get; } = name;
|
||||
public string[] Parameters { get; } = parameters;
|
||||
public string Table { get; init; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
namespace LuaScript.Api
|
||||
{
|
||||
internal static class LuaCompletionSource
|
||||
{
|
||||
internal static readonly string[] Keywords =
|
||||
[
|
||||
"and", "break", "do", "else", "elseif", "end", "false", "for",
|
||||
"function", "goto", "if", "in", "local", "nil", "not", "or",
|
||||
"repeat", "return", "then", "true", "until", "while"
|
||||
];
|
||||
|
||||
private sealed record Snapshot(
|
||||
int Version,
|
||||
string[] StaticCandidates,
|
||||
IReadOnlyDictionary<string, string[]> TableMembers);
|
||||
|
||||
private static Snapshot? s_snapshot;
|
||||
|
||||
internal static string[] StaticCandidates => Current().StaticCandidates;
|
||||
|
||||
internal static bool TryGetTableMembers(string table, out string[] members)
|
||||
{
|
||||
if (Current().TableMembers.TryGetValue(table, out var found))
|
||||
{
|
||||
members = found;
|
||||
return true;
|
||||
}
|
||||
members = [];
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Snapshot Current()
|
||||
{
|
||||
var snapshot = s_snapshot;
|
||||
int version = LuaApiCatalog.Version;
|
||||
if (snapshot is null || snapshot.Version != version)
|
||||
s_snapshot = snapshot = Build(version);
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
private static Snapshot Build(int version)
|
||||
{
|
||||
var members = LuaApiCatalog.Members;
|
||||
|
||||
var tableMembers = new Dictionary<string, List<string>>(StringComparer.Ordinal);
|
||||
var globals = new List<string>();
|
||||
foreach (var member in members)
|
||||
{
|
||||
if (member.Table.Length == 0)
|
||||
{
|
||||
globals.Add(member.Name);
|
||||
continue;
|
||||
}
|
||||
if (!tableMembers.TryGetValue(member.Table, out var list))
|
||||
{
|
||||
list = [];
|
||||
tableMembers[member.Table] = list;
|
||||
}
|
||||
list.Add(member.QualifiedName);
|
||||
}
|
||||
|
||||
var candidates = Keywords
|
||||
.Concat(globals)
|
||||
.Concat(tableMembers.Keys)
|
||||
.Concat(tableMembers.Values.SelectMany(x => x))
|
||||
.Distinct()
|
||||
.OrderBy(x => x.Length)
|
||||
.ThenBy(x => x, StringComparer.OrdinalIgnoreCase)
|
||||
.ToArray();
|
||||
|
||||
var frozen = new Dictionary<string, string[]>(StringComparer.Ordinal);
|
||||
foreach (var (table, list) in tableMembers)
|
||||
frozen[table] = [.. list.Distinct()];
|
||||
|
||||
return new Snapshot(version, candidates, frozen);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace LuaScript.Api
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = false)]
|
||||
internal sealed class LuaConstantAttribute(string name) : Attribute
|
||||
{
|
||||
public string Name { get; } = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace LuaScript.Api
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, Inherited = false, AllowMultiple = true)]
|
||||
internal sealed class LuaFunctionAttribute(string name, params string[] parameters) : Attribute
|
||||
{
|
||||
public string Name { get; } = name;
|
||||
public string[] Parameters { get; } = parameters;
|
||||
public string Table { get; init; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
namespace LuaScript.Api
|
||||
{
|
||||
[LuaTable("math")]
|
||||
[LuaBuiltin("abs", "x")]
|
||||
[LuaBuiltin("ceil", "x")]
|
||||
[LuaBuiltin("cos", "x")]
|
||||
[LuaBuiltin("exp", "x")]
|
||||
[LuaBuiltin("floor", "x")]
|
||||
[LuaBuiltin("fmod", "x", "y")]
|
||||
[LuaVariable("huge")]
|
||||
[LuaBuiltin("log", "x", "base")]
|
||||
[LuaBuiltin("max", "x", "...")]
|
||||
[LuaBuiltin("min", "x", "...")]
|
||||
[LuaBuiltin("modf", "x")]
|
||||
[LuaVariable("pi")]
|
||||
[LuaBuiltin("random", "m", "n")]
|
||||
[LuaBuiltin("randomseed", "x")]
|
||||
[LuaBuiltin("sin", "x")]
|
||||
[LuaBuiltin("sqrt", "x")]
|
||||
[LuaBuiltin("tan", "x")]
|
||||
[LuaBuiltin("atan", "y", "x")]
|
||||
[LuaBuiltin("atan2", "y", "x")]
|
||||
[LuaBuiltin("deg", "x")]
|
||||
[LuaBuiltin("rad", "x")]
|
||||
[LuaBuiltin("ldexp", "m", "e")]
|
||||
[LuaBuiltin("frexp", "x")]
|
||||
[LuaBuiltin("sinh", "x")]
|
||||
[LuaBuiltin("cosh", "x")]
|
||||
[LuaBuiltin("tanh", "x")]
|
||||
[LuaBuiltin("type", "x")]
|
||||
[LuaBuiltin("tointeger", "x")]
|
||||
[LuaVariable("maxinteger")]
|
||||
[LuaVariable("mininteger")]
|
||||
internal static class LuaMathLibrary;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace LuaScript.Api
|
||||
{
|
||||
[LuaTable("string")]
|
||||
[LuaBuiltin("format", "formatstring", "...")]
|
||||
[LuaBuiltin("len", "s")]
|
||||
[LuaBuiltin("sub", "s", "i", "j")]
|
||||
[LuaBuiltin("upper", "s")]
|
||||
[LuaBuiltin("lower", "s")]
|
||||
[LuaBuiltin("rep", "s", "n", "sep")]
|
||||
[LuaBuiltin("reverse", "s")]
|
||||
[LuaBuiltin("find", "s", "pattern", "init", "plain")]
|
||||
[LuaBuiltin("match", "s", "pattern", "init")]
|
||||
[LuaBuiltin("gmatch", "s", "pattern")]
|
||||
[LuaBuiltin("gsub", "s", "pattern", "repl", "n")]
|
||||
[LuaBuiltin("byte", "s", "i", "j")]
|
||||
[LuaBuiltin("char", "...")]
|
||||
[LuaBuiltin("dump", "function")]
|
||||
[LuaBuiltin("pack", "fmt", "...")]
|
||||
[LuaBuiltin("unpack", "fmt", "s", "pos")]
|
||||
[LuaBuiltin("packsize", "fmt")]
|
||||
internal static class LuaStringLibrary;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace LuaScript.Api
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
|
||||
internal sealed class LuaTableAttribute(string name) : Attribute
|
||||
{
|
||||
public string Name { get; } = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace LuaScript.Api
|
||||
{
|
||||
[LuaTable("table")]
|
||||
[LuaBuiltin("insert", "list", "pos", "value")]
|
||||
[LuaBuiltin("remove", "list", "pos")]
|
||||
[LuaBuiltin("sort", "list", "comp")]
|
||||
[LuaBuiltin("concat", "list", "sep", "i", "j")]
|
||||
[LuaBuiltin("unpack", "list", "i", "j")]
|
||||
[LuaBuiltin("move", "a1", "f", "e", "t", "a2")]
|
||||
internal static class LuaTableLibrary;
|
||||
}
|
||||
199ファイル中100ファイルを読み込みました。 変更されたファイルが多すぎるため、それ以降のファイルは表示していません。
さらに表示
新しいイシューから参照
ユーザーをブロックする