宣言的 API カタログ基盤を追加し生成器を接続
このコミットが含まれているのは:
6ファイル変更
+273
-1
検索条件に一致するファイルはありません
@@ -0,0 +1,38 @@
|
||||
namespace LuaScript.Api
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
|
||||
internal sealed class LuaTableAttribute(string name) : Attribute
|
||||
{
|
||||
public string Name { get; } = name;
|
||||
}
|
||||
|
||||
[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;
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = false)]
|
||||
internal sealed class LuaConstantAttribute(string name) : Attribute
|
||||
{
|
||||
public string Name { get; } = name;
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Assembly | AttributeTargets.Method, Inherited = false, AllowMultiple = true)]
|
||||
internal sealed class LuaVariableAttribute(string name) : Attribute
|
||||
{
|
||||
public string Name { get; } = name;
|
||||
public string Table { get; init; } = string.Empty;
|
||||
public bool InCatalog { get; init; } = true;
|
||||
}
|
||||
|
||||
[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,53 @@
|
||||
namespace LuaScript.Api
|
||||
{
|
||||
internal enum LuaApiMemberKind
|
||||
{
|
||||
Function,
|
||||
Variable,
|
||||
}
|
||||
|
||||
internal sealed record LuaApiMember(
|
||||
string Table,
|
||||
string Name,
|
||||
LuaApiMemberKind Kind,
|
||||
IReadOnlyList<string> Parameters)
|
||||
{
|
||||
public string QualifiedName => Table.Length == 0 ? Name : $"{Table}.{Name}";
|
||||
}
|
||||
|
||||
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,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,101 @@
|
||||
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;
|
||||
|
||||
[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;
|
||||
|
||||
[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;
|
||||
|
||||
[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;
|
||||
|
||||
[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;
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする