コミットを比較

...
45 コミット
作成者 SHA1 メッセージ 日付
routersys f26816343f バージョンをv1.13.4へ更新
リリース / build-and-release (workflow_dispatch) Actions がタグ v1.13.4 のコミットから作成しました
2026-07-03 19:26:11 +09:00
routersys 0cab8972e0 READMEにobj.getinfoを追記 2026-07-03 19:18:26 +09:00
routersys f2aa668cf6 サイトにobj.getinfoの説明を追加 2026-07-03 19:17:45 +09:00
routersys ed27979f64 各言語ドキュメントにobj.getinfoを追記 2026-07-03 19:15:46 +09:00
routersys 7b958ea171 obj.getinfoの実行テストを追加 2026-07-03 19:11:12 +09:00
routersys 332dab3889 補完目録にobj.getinfoを追加 2026-07-03 19:11:05 +09:00
routersys 75d457a7ab プラグインからgetinfoへ情報を供給 2026-07-03 19:10:58 +09:00
routersys 50e1801878 MoonSharpにobj.getinfoを実装 2026-07-03 19:10:52 +09:00
routersys 793d010bdb ネイティブにobj.getinfoを実装 2026-07-03 19:10:45 +09:00
routersys b564b0b185 script_pathをワーカー起動引数へ渡す 2026-07-03 19:10:39 +09:00
routersys 6d83fe93d8 getinfo情報をネイティブフィールドへ転送 2026-07-03 19:10:32 +09:00
routersys db9c3747ea getinfo用のネイティブフィールド枠を追加 2026-07-03 19:10:27 +09:00
routersys 7d887afe5a getinfo用の環境情報フィールドを追加 2026-07-03 19:10:21 +09:00
routersys ac34830367 ViewModelをフレームワーク非依存へ整理 2026-07-03 18:29:48 +09:00
routersys 8ed188d0e2 ツールバーをView/ViewModelへMVVM分離 2026-07-03 18:10:21 +09:00
routersys 9c55c08caf エフェクト本体をEffectsフォルダへ整理 2026-07-03 18:02:53 +09:00
routersys 42868023f3 メディア/シーン解決をEngine・Sceneへ整理 2026-07-03 18:02:49 +09:00
routersys e146b36fa0 描画合成をDrawingフォルダへ整理 2026-07-03 18:02:45 +09:00
routersys 5fac495848 エディタ関連をEditorフォルダへ整理 2026-07-03 18:02:42 +09:00
routersys 4fd519249f Texts をLocalizationフォルダへ集約 2026-07-03 17:59:54 +09:00
routersys 1b26df959f デコーダを LuaScript.Media プロジェクトへ分離 2026-07-03 17:25:43 +09:00
routersys 3cd67212a1 Compat を1ファイル1クラス化しフォルダへ整理 2026-07-03 17:11:46 +09:00
routersys 46692dfe95 Compat の重複パーサを ScriptParserHelper へ集約 2026-07-03 17:08:16 +09:00
routersys e8d9cef129 KFunc メタデータを単一カタログへ集約 2026-07-03 16:59:34 +09:00
routersys 18036cd74e Kernel を1ファイル1クラス化しフォルダへ整理 2026-07-03 16:58:14 +09:00
routersys c8f857d2b4 MoonSharpBit32 を Compat プロジェクトへ移動 2026-07-03 16:31:01 +09:00
routersys ac7f797566 Scene 値型を1ファイル1クラス化 2026-07-03 16:18:13 +09:00
routersys 8beae1a277 Diagnostics のトップレベル型を1ファイル1クラス化 2026-07-03 16:18:04 +09:00
routersys 6eb4d7c9af Anchor のトップレベル型を1ファイル1クラス化 2026-07-03 16:17:55 +09:00
routersys a843f460de Api のトップレベル型を1ファイル1クラス化 2026-07-03 16:17:45 +09:00
routersys 27f04c7560 テーブル登録を LuaScope で汎用化 2026-07-03 16:17:35 +09:00
routersys 43c0ce88b3 エンジンのテーブルライフサイクル特性化テストを追加 2026-07-03 16:17:27 +09:00
routersys 00f0d991c1 Runtime のファイルをドメイン別フォルダへ整理 2026-07-03 14:13:33 +09:00
routersys 784d294ca6 補完カタログの回帰テストを追加 2026-07-03 14:05:16 +09:00
routersys 260d427bcf 補完ストラテジをカタログ消費へ置換 2026-07-03 14:05:14 +09:00
routersys b62f4a3a7d 登録と毎フレーム変数を属性ベース生成へ移行 2026-07-03 14:05:12 +09:00
routersys 79a408cafd 宣言的 API カタログ基盤を追加し生成器を接続 2026-07-03 14:05:11 +09:00
routersys 807df7df8a Lua API ソースジェネレータを新設 2026-07-03 14:05:10 +09:00
routersys 0c5e3066c1 リリース配布物へ分離アセンブリを追加 2026-07-03 11:50:45 +09:00
routersys fbaff95503 テストをリンク方式から ProjectReference へ移行 2026-07-03 11:50:43 +09:00
routersys 8dec38a911 ソリューションへ分離プロジェクトを追加 2026-07-03 11:50:42 +09:00
routersys 902d729c19 プラグイン本体を分離プロジェクト参照へ移行 2026-07-03 11:50:40 +09:00
routersys 79f8ff8839 LuaScript.Runtime へ実行コアを分離し依存を逆転 2026-07-03 11:50:23 +09:00
routersys 9a630ecb5a LuaScript.Compat を新設し AviUtl 互換層を移設 2026-07-03 11:50:08 +09:00
routersys d9e6132a1f LuaScript.Kernel を新設しカーネルコンパイラ群を移設 2026-07-03 11:49:33 +09:00
198個のファイルの変更、3911行の追加、2096行の削除

検索条件に一致するファイルはありません

+25 -28
ファイルの表示
@@ -1,46 +1,43 @@
# v1.13.3 - Lua スクリプト for YMM4
# v1.13.4 - Lua スクリプト for YMM4
obj.setfont の引数の解釈を MoonSharp とネイティブの両エンジンで統一したリリースです。
これまで両エンジンは通常の呼び出しでは同じ結果を返していましたが、引数へ想定外の型や値を渡した場合の挙動が食い違っており、ネイティブエンジンにはスクリプト全体をエラーにする経路が存在しました。今回から、どのような引数を渡しても両エンジンが同一の結果を返します。
あわせて、スクリプトエディタの入力補完へ、ドキュメントに記載済みで未登録だった obj テーブルの関数 12 件を追加しました。
呼び出しの書き方と関数の引数に変更はありません。通常の使い方への影響はありません。
環境情報を取得する obj.getinfo を追加したリリースです。
スクリプトの設置フォルダのパスや動画の出力状態に加えて、最大画像サイズ、BPMグリッドの情報、経過時間、本体のバージョンを名前で取得できます。MoonSharp とネイティブの両エンジンで同一の関数として動作します。
あわせて、プラグインの内部構成を依存関係の層ごとの複数アセンブリへ分割し、Lua API の登録と入力補完をソースジェネレータによる宣言的な生成へ移行しました。既存のスクリプトの書き方と実行結果に変更はありません。
---
## 動作の変更
## 新機能
### 1. obj.setfont の引数の解釈を両エンジンで統一
### obj.getinfo による環境情報の取得
obj.setfont(フォント名, サイズ, スタイル, 色) の各引数について、想定外の型や値を渡した場合の挙動を次のとおり統一しました。
obj.getinfo(名前) は、名前で指定した環境情報を返します。対応していない名前を指定した場合は nil を返します。取得できる情報は次のとおりです。
- フォント名へ数値を渡した場合、両エンジンとも文字列へ変換して採用します。これまで MoonSharp は無視し、ネイティブは真偽値やテーブルまで文字列化していました。文字列と数値以外の値は両エンジンとも無視し、直前の設定を保持します。
- サイズへ数値文字列を渡した場合、両エンジンとも数値へ変換して採用します。これまでネイティブは文字列のまま保持し、後続の obj.load("text") の呼び出しでスクリプト全体が実行時エラーになっていました。数値へ変換できない値は両エンジンとも無視し、直前の設定を保持します。
- スタイルへ数値へ変換できない値を渡した場合、両エンジンとも無視して直前の設定を保持します。これまで MoonSharp は 0 として太字と斜体を解除し、ネイティブは実行時エラーになっていました。
- スタイルの小数と負数は、両エンジンとも床関数で整数化してからビットを判定します。これまで MoonSharp はゼロ方向への切り捨てを行っており、負の小数で結果が食い違っていました。
- スタイルへ NaN・無限大・2^53 を超える数値を渡した場合も、両エンジンとも同一の結果(太字と斜体の解除)になります。これまで MoonSharp は変換の飽和により値ごとに異なるフラグが立つことがありました。
- 色へ数値へ変換できない値を渡した場合、両エンジンとも無視して直前の設定を保持します。
- "script_path" は、プラグインの設置フォルダのパスを返します。末尾には区切り文字が付きます。
- "filter" は、フィルタ効果として処理中かどうかを返します。本プラグインでは常に true を返します。
- "saving" は、動画を出力中のときだけ true を返します。
- "image_max" は、最大画像サイズを横幅と高さの2つの値で返します。
- "bpm" は、BPMグリッドのテンポと拍子と基準時間の3つの値を返します。基準時間の単位は秒です。BPMグリッドを設定していない場合はテンポが 0 になります。
- "clock" は、YMM4 の起動からの経過時間を秒で返します。
- "script_time" は、スクリプトの実行開始からの経過時間をミリ秒で返します。
- "version" は、本体のバージョンを major×10000+minor×100+build の数値で返します。
### 2. スクリプトエディタの入力補完へ obj テーブルの関数 12 件を追加
ドキュメントに記載済みで入力補完に未登録だった次の関数を、候補へ追加しました。
obj.getobject、obj.putpixeldata、obj.setfont、obj.draw、obj.drawpoly、obj.copybuffer、obj.getvalue、obj.setoption、obj.getoption、obj.pixeloption、obj.setanchor、obj.effect の 12 件です。
並び順はドキュメントの「obj テーブル - 関数」の記載順に合わせています。
編集中のみプレビューへ枠を描き、出力時には描かないといった分岐へ利用できます。
---
## 互換性・後方互換
- 呼び出しの書き方と関数の引数に変更はありません。フォント名に文字列、サイズ・スタイル・色に数値を渡す通常の使い方の結果は変わりません。
- 引数を省略した場合と nil を渡した場合は、両エンジンとも直前の設定を保持します。
- フォントの既定値(フォント名なし・サイズ 34・標準スタイル・色 0xFFFFFF)と、実行ごとに既定値へ戻る仕様は変わりません。
- scene.set / scene.get を含む v1.13.2 の仕様に変更はありません。
- 既存のスクリプトの書き方と実行結果に変更はありません。obj.getinfo は新規の関数であり、従来の呼び出しへは影響しません。
- obj.getinfo は MoonSharp とネイティブの両エンジンで動作します。script_path、filter、saving、image_max、bpm、version は両エンジンで同一の値を返します。clock と script_time は経過時間の計測であり、値そのものは実行のたびに変わります。
- v1.13.3 までの仕様に変更はありません。
---
## 内部実装
- MoonSharp 側の setfont の引数解釈とフォント状態を AviUtlFontState として独立した型へ抽出しました。LuaScriptEngine はフォントの 5 つのフィールドを持たず、この型へ委譲します。テストレーンはソースリンク方式で LuaScriptEngine を参照できないため、SceneTableRegistrar と同じ「純粋な単位を切り出してリンクする」構成に従ったものです。
- スタイルのビット判定は Lua の剰余と同じ床剰余(値 - floor(値 / 除数) * 除数)で行います。C# の変換の飽和(NaN が 0、範囲外が最大値へ丸められる仕様)を経由しないため、非有限値と巨大な値でも LuaJIT の math.floor と剰余の結果に一致します。
- worker.lua の setfont へ型検査と tonumber による変換を導入しました。フォント名は文字列と数値のみ受理し、サイズ・スタイル・色は数値へ変換できた場合のみ採用します。変換できない値が共有メモリの数値領域へ渡って ffi の変換エラーになる経路を排除しました。
- 入力補完は LuaAutoCompletionStrategy の obj 名前空間の候補配列への追加のみで、補完の仕組みに変更はありません。
- テストは 3092 件です。v1.13.2 の 3086 件から、AviUtlFontState の既定値とリセット、引数の変換規則、負数スタイルの床セマンティクス、非有限値の扱いの検証と、ネイティブワーカーで同一の呼び出し列を実行して同じ期待値と照合する等価性の検証を追加しました。
- プラグインを依存関係の層ごとに 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 -1
ファイルの表示
@@ -1,5 +1,5 @@
========================================
Luaスクリプト for YMM4 v1.13.3
Luaスクリプト for YMM4 v1.13.4
========================================
YukkuriMovieMaker4(YMM4)上で動作する、Luaスクリプトで映像エフェクトのパラメータや
ピクセルを直接制御できるプラグインです。
+4
ファイルの表示
@@ -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/"
ファイルの表示
差分なしでファイル名を変更。
差分なしでファイル名を変更。
ファイルの表示
差分なしでファイル名を変更。
ファイルの表示
差分なしでファイル名を変更。
差分なしでファイル名を変更。
+25
ファイルの表示
@@ -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>
+1 -1
ファイルの表示
@@ -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))
@@ -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;
+9
ファイルの表示
@@ -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) =>
+7
ファイルの表示
@@ -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;
}
}
差分なしでファイル名を変更。
@@ -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))
+3 -38
ファイルの表示
@@ -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))
{
差分なしでファイル名を変更。
+69
ファイルの表示
@@ -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;
}
}
}
+45
ファイルの表示
@@ -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();
}
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace System.Runtime.CompilerServices
{
internal static class IsExternalInit;
}
+486
ファイルの表示
@@ -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)];
}
}
}
+21
ファイルの表示
@@ -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>
差分なしでファイル名を変更。
差分なしでファイル名を変更。
@@ -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)
@@ -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;
差分なしでファイル名を変更。
差分なしでファイル名を変更。
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record KArith(KArithOp Op, KExpr Left, KExpr Right) : KExpr;
}
+12
ファイルの表示
@@ -0,0 +1,12 @@
namespace LuaScript.Engine.Kernel
{
internal enum KArithOp
{
Add,
Subtract,
Multiply,
Divide,
Modulo,
Power,
}
}
+8
ファイルの表示
@@ -0,0 +1,8 @@
namespace LuaScript.Engine.Kernel
{
internal enum KAxis
{
X,
Y,
}
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal abstract record KBool;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record KBoolConst(bool Value) : KBool;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record KCall(KFunc Func, IReadOnlyList<KExpr> Arguments) : KExpr;
}
+10
ファイルの表示
@@ -0,0 +1,10 @@
namespace LuaScript.Engine.Kernel
{
internal enum KChannel
{
R,
G,
B,
A,
}
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record KCompare(KCompareOp Op, KExpr Left, KExpr Right) : KBool;
}
+12
ファイルの表示
@@ -0,0 +1,12 @@
namespace LuaScript.Engine.Kernel
{
internal enum KCompareOp
{
Less,
Greater,
LessEqual,
GreaterEqual,
Equal,
NotEqual,
}
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record KConst(double Value) : KExpr;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record KCoord(KAxis Axis) : KExpr;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal abstract record KExpr;
}
+23
ファイルの表示
@@ -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,
}
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal readonly record struct KFunctionInfo(KFunc Func, string Name, int MinArgs, int MaxArgs);
}
+52
ファイルの表示
@@ -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;
}
}
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record KInput(KChannel Channel) : KExpr;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record KLocalRef(int Slot) : KExpr;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record KLogical(bool IsAnd, KBool Left, KBool Right) : KBool;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record KNegate(KExpr Operand) : KExpr;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record KNot(KBool Operand) : KBool;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record KSelect(KBool Condition, KExpr WhenTrue, KExpr WhenFalse) : KExpr;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record KUniformRef(KernelUniform Uniform) : KExpr;
}
+10
ファイルの表示
@@ -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);
}
+60
ファイルの表示
@@ -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,
}
}
-58
ファイルの表示
@@ -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;
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record AssignStmt(IReadOnlyList<LuaExpr> Targets, IReadOnlyList<LuaExpr> Values) : LuaStmt;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record BinaryExpr(string Operator, LuaExpr Left, LuaExpr Right) : LuaExpr;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record BoolExpr(bool Value) : LuaExpr;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record CallExpr(LuaExpr Target, IReadOnlyList<LuaExpr> Arguments) : LuaExpr;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record CallStmt(LuaExpr Call) : LuaStmt;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record IfClause(LuaExpr Condition, IReadOnlyList<LuaStmt> Body);
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record IfStmt(IReadOnlyList<IfClause> Clauses, IReadOnlyList<LuaStmt>? ElseBody) : LuaStmt;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record IndexExpr(LuaExpr Target, LuaExpr Key) : LuaExpr;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record LocalStmt(IReadOnlyList<string> Names, IReadOnlyList<LuaExpr> Values) : LuaStmt;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal abstract record LuaExpr;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal abstract record LuaStmt;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record MemberExpr(LuaExpr Target, string Name) : LuaExpr;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record MethodCallExpr(LuaExpr Target, string Method, IReadOnlyList<LuaExpr> Arguments) : LuaExpr;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record NameExpr(string Name) : LuaExpr;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record NilExpr : LuaExpr;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record NumberExpr(double Value) : LuaExpr;
}
+9
ファイルの表示
@@ -0,0 +1,9 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record NumericForStmt(
string Variable,
LuaExpr Start,
LuaExpr Stop,
LuaExpr? Step,
IReadOnlyList<LuaStmt> Body) : LuaStmt;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record StringExpr(string Value) : LuaExpr;
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Engine.Kernel
{
internal sealed record UnaryExpr(string Operator, LuaExpr Operand) : LuaExpr;
}
ファイルの表示
差分なしでファイル名を変更。
ファイルの表示
差分なしでファイル名を変更。
-10
ファイルの表示
@@ -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;
+12
ファイルの表示
@@ -0,0 +1,12 @@
namespace LuaScript.Engine.Kernel
{
internal enum LuaTokenKind
{
Name,
Number,
String,
Keyword,
Symbol,
Eof,
}
}
+18
ファイルの表示
@@ -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>
ファイルの表示
差分なしでファイル名を変更。
+48
ファイルの表示
@@ -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>
ファイルの表示
差分なしでファイル名を変更。
ファイルの表示
差分なしでファイル名を変更。
+11
ファイルの表示
@@ -0,0 +1,11 @@
namespace LuaScript.Anchor
{
internal enum AnchorConnection
{
None,
Line,
Loop,
Star,
Arm,
}
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Anchor
{
internal readonly record struct AnchorOptions(AnchorConnection Connection, bool Is3D);
}
+4
ファイルの表示
@@ -0,0 +1,4 @@
namespace LuaScript.Anchor
{
internal readonly record struct AnchorRequestData(string Group, int Count, AnchorConnection Connection, bool Is3D);
}
-15
ファイルの表示
@@ -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;
差分なしでファイル名を変更。
+38
ファイルの表示
@@ -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];
}
}
}
}
+11
ファイルの表示
@@ -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}";
}
}
+8
ファイルの表示
@@ -0,0 +1,8 @@
namespace LuaScript.Api
{
internal enum LuaApiMemberKind
{
Function,
Variable,
}
}
+24
ファイルの表示
@@ -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;
}
+17
ファイルの表示
@@ -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;
}
+10
ファイルの表示
@@ -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;
}
}
+78
ファイルの表示
@@ -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);
}
}
}
+8
ファイルの表示
@@ -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;
}
}
+10
ファイルの表示
@@ -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;
}
}
+35
ファイルの表示
@@ -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;
}
+22
ファイルの表示
@@ -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;
}
+8
ファイルの表示
@@ -0,0 +1,8 @@
namespace LuaScript.Api
{
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
internal sealed class LuaTableAttribute(string name) : Attribute
{
public string Name { get; } = name;
}
}
+11
ファイルの表示
@@ -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;
}
198ファイル中100ファイルを読み込みました。 変更されたファイルが多すぎるため、それ以降のファイルは表示していません。 さらに表示