Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Lua.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp1", "sandbox\Cons
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmark", "sandbox\Benchmark\Benchmark.csproj", "{FC157C29-8AAE-49C8-9536-208E3F0698DA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lua.SourceGenerator", "src\Lua.SourceGenerator\Lua.SourceGenerator.csproj", "{C4BB264C-4D37-4E2D-99FD-4918CE22D7E4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -42,11 +44,16 @@ Global
{FC157C29-8AAE-49C8-9536-208E3F0698DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FC157C29-8AAE-49C8-9536-208E3F0698DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC157C29-8AAE-49C8-9536-208E3F0698DA}.Release|Any CPU.Build.0 = Release|Any CPU
{C4BB264C-4D37-4E2D-99FD-4918CE22D7E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C4BB264C-4D37-4E2D-99FD-4918CE22D7E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C4BB264C-4D37-4E2D-99FD-4918CE22D7E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C4BB264C-4D37-4E2D-99FD-4918CE22D7E4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{6E33BFBC-E51F-493E-9AF0-30C1100F5B5D} = {18A64E25-9557-457B-80AE-A6EFE853118D}
{7572B7BC-FC73-42F0-B4F7-DA291B4EDB36} = {79458370-DD8A-48A4-B11E-8DF631520E8C}
{718A361C-AAF3-45A4-84D4-8C4FB6BB374E} = {33883F28-679F-48AD-8E64-3515C7BDAF5A}
{FC157C29-8AAE-49C8-9536-208E3F0698DA} = {33883F28-679F-48AD-8E64-3515C7BDAF5A}
{C4BB264C-4D37-4E2D-99FD-4918CE22D7E4} = {18A64E25-9557-457B-80AE-A6EFE853118D}
EndGlobalSection
EndGlobal
7 changes: 7 additions & 0 deletions sandbox/ConsoleApp1/ConsoleApp1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

<ItemGroup>
<ProjectReference Include="..\..\src\Lua\Lua.csproj" />
<ProjectReference Include="..\..\src\Lua.SourceGenerator\Lua.SourceGenerator.csproj">
<OutputItemType>Analyzer</OutputItemType>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<EmitCompilerGeneratedFiles>false</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

</Project>
43 changes: 43 additions & 0 deletions sandbox/ConsoleApp1/LVec3.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Numerics;
using Lua;

[LuaObject]
public partial class LVec3
{
Vector3 value;

[LuaMember("x")]
public float X
{
get => value.X;
set => this.value = this.value with { X = value };
}

[LuaMember("y")]
public float Y
{
get => value.Y;
set => this.value = this.value with { Y = value };
}

[LuaMember("z")]
public float Z
{
get => value.Z;
set => this.value = this.value with { Z = value };
}

[LuaMember("create")]
public static LVec3 Create(float x, float y, float z)
{
return new LVec3()
{
value = new Vector3(x, y, z)
};
}

public override string ToString()
{
return value.ToString();
}
}
2 changes: 2 additions & 0 deletions sandbox/ConsoleApp1/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
var state = LuaState.Create();
state.OpenStandardLibraries();

state.Environment["vec3"] = new LVec3();

try
{
var source = File.ReadAllText("test.lua");
Expand Down
58 changes: 0 additions & 58 deletions sandbox/ConsoleApp1/vec3.lua

This file was deleted.

18 changes: 18 additions & 0 deletions src/Lua.SourceGenerator/Comparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Microsoft.CodeAnalysis;

namespace Lua.SourceGenerator;

internal sealed class Comparer : IEqualityComparer<(GeneratorAttributeSyntaxContext, Compilation)>
{
public static readonly Comparer Instance = new();

public bool Equals((GeneratorAttributeSyntaxContext, Compilation) x, (GeneratorAttributeSyntaxContext, Compilation) y)
{
return x.Item1.TargetNode.Equals(y.Item1.TargetNode);
}

public int GetHashCode((GeneratorAttributeSyntaxContext, Compilation) obj)
{
return obj.Item1.TargetNode.GetHashCode();
}
}
64 changes: 64 additions & 0 deletions src/Lua.SourceGenerator/DiagnosticDescriptors.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Microsoft.CodeAnalysis;

namespace Lua.SourceGenerator;

public static class DiagnosticDescriptors
{
const string Category = "Lua";

public static readonly DiagnosticDescriptor MustBePartial = new(
id: "LUACS001",
title: "LuaObject type must be partial.",
category: Category,
messageFormat: "LuaObject type '{0}' must be partial",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true);

public static readonly DiagnosticDescriptor NestedNotAllowed = new(
id: "LUACS002",
title: "LuaObject type must not be nested",
messageFormat: "LuaObject type '{0}' must be not nested",
category: Category,
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true);

public static readonly DiagnosticDescriptor AbstractNotAllowed = new(
id: "LUACS003",
title: "LuaObject type must not abstract",
messageFormat: "LuaObject object '{0}' must be not abstract",
category: Category,
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true);

public static readonly DiagnosticDescriptor InvalidPropertyType = new(
id: "LUACS004",
title: "The type of the field or property must be LuaValue or a type that can be converted to LuaValue.",
messageFormat: "The type of '{0}' must be LuaValue or a type that can be converted to LuaValue.",
category: Category,
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true);

public static readonly DiagnosticDescriptor InvalidReturnType = new(
id: "LUACS005",
title: "The return type must be LuaValue or types that can be converted to LuaValue.",
messageFormat: "The return type '{0}' must be LuaValue or types that can be converted to LuaValue.",
category: Category,
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true);

public static readonly DiagnosticDescriptor InvalidParameterType = new(
id: "LUACS006",
title: "The parameters must be LuaValue or types that can be converted to LuaValue.",
messageFormat: "The parameter '{0}' must be LuaValue or types that can be converted to LuaValue.",
category: Category,
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true);

public static readonly DiagnosticDescriptor DuplicateMetamethod = new(
id: "LUACS007",
title: "The type already contains same metamethod.",
messageFormat: "Type '{0}' already contains a '{1}' metamethod.,",
category: Category,
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true);
}
23 changes: 23 additions & 0 deletions src/Lua.SourceGenerator/Lua.SourceGenerator.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>12</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsRoslynComponent>true</IsRoslynComponent>
<AnalyzerLanguage>cs</AnalyzerLanguage>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<IncludeBuildOutput>false</IncludeBuildOutput>
<DevelopmentDependency>true</DevelopmentDependency>
<IncludeSymbols>false</IncludeSymbols>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.0" />

<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
</ItemGroup>

</Project>
Loading