Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghuan committed Feb 3, 2018
1 parent 00f5f0f commit 41e47f1
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 16 deletions.
12 changes: 12 additions & 0 deletions CSharp.lua.Launcher/CSharp.lua.Launcher.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\CSharp.lua\CSharp.lua.csproj" />
</ItemGroup>

</Project>
92 changes: 92 additions & 0 deletions CSharp.lua.Launcher/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
Copyright 2017 YANG Huan ([email protected]).
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharpLua {
class Program {
private const string HelpCmdString = @"Usage: CSharp.lua [-s srcfolder] [-d dstfolder]
Arguments
-s : source directory, all *.cs files whill be compiled
-d : destination directory, will put the out lua files
Options
-h : show the help message
-l : libraries referenced, use ';' to separate
-m : meta files, like System.xml, use ';' to separate
-csc : csc.exe command argumnets, use ';' to separate
-c : support classic lua version(5.1), default support 5.3
-i : indent number, default is 2
-a : attributes need to export, use ';' to separate, if ""-a"" only, all attributes whill be exported
";
public static void Main(string[] args) {
if (args.Length > 0) {
try {
var cmds = Utility.GetCommondLines(args);
if (cmds.ContainsKey("-h")) {
ShowHelpInfo();
return;
}

Console.WriteLine($"start {DateTime.Now}");

string folder = cmds.GetArgument("-s");
string output = cmds.GetArgument("-d");
string lib = cmds.GetArgument("-l", true);
string meta = cmds.GetArgument("-m", true);
string csc = cmds.GetArgument("-csc", true);
bool isClassic = cmds.ContainsKey("-c");
string indent = cmds.GetArgument("-i", true);
string atts = cmds.GetArgument("-a", true);
if (atts == null && cmds.ContainsKey("-a")) {
atts = string.Empty;
}
Worker w = new Worker(folder, output, lib, meta, csc, isClassic, indent, atts);
w.Do();
Console.WriteLine("all operator success");
Console.WriteLine($"end {DateTime.Now}");
}
catch (CmdArgumentException e) {
Console.Error.WriteLine(e.Message);
ShowHelpInfo();
Environment.ExitCode = -1;
}
catch (CompilationErrorException e) {
Console.Error.WriteLine(e.Message);
Environment.ExitCode = -1;
}
catch (Exception e) {
Console.Error.WriteLine(e.ToString());
Environment.ExitCode = -1;
}
}
else {
ShowHelpInfo();
Environment.ExitCode = -1;
}
}

private static void ShowHelpInfo() {
Console.Error.WriteLine(HelpCmdString);
}
}
}
8 changes: 7 additions & 1 deletion CSharp.lua.sln
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.3
VisualStudioVersion = 15.0.27130.2027
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSharp.lua", "CSharp.lua\CSharp.lua.csproj", "{0CF2866D-CB70-4E0A-84DB-B09D6FC9948C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharp.lua.Launcher", "CSharp.lua.Launcher\CSharp.lua.Launcher.csproj", "{5D512FF6-7C1D-44EE-934C-2E970AA1BFB4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{0CF2866D-CB70-4E0A-84DB-B09D6FC9948C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0CF2866D-CB70-4E0A-84DB-B09D6FC9948C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0CF2866D-CB70-4E0A-84DB-B09D6FC9948C}.Release|Any CPU.Build.0 = Release|Any CPU
{5D512FF6-7C1D-44EE-934C-2E970AA1BFB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5D512FF6-7C1D-44EE-934C-2E970AA1BFB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5D512FF6-7C1D-44EE-934C-2E970AA1BFB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5D512FF6-7C1D-44EE-934C-2E970AA1BFB4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
7 changes: 2 additions & 5 deletions CSharp.lua/CSharp.lua.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<!--<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>-->
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.1.0</Version>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Copyright>Copyright © YANG Huan 2017</Copyright>
Expand All @@ -16,7 +13,7 @@
</PropertyGroup>

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

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions CSharp.lua/CoreSystem.Lua/CoreSystem/Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,6 @@ defCls("System.ValueType", ValueType)
local AnonymousType = {}
defCls("System.AnonymousType", AnonymousType)

defCls("System.Attribute", {})

function System.anonymousType(t)
return setmetatable(t, AnonymousType)
end
Expand All @@ -944,6 +942,8 @@ function System.valueTuple(t)
return setmetatable(t, ValueTuple)
end

defCls("System.Attribute", {})

debug.setmetatable(nil, {
__concat = function(a, b)
if a == nil then
Expand Down
2 changes: 1 addition & 1 deletion CSharp.lua/LuaSyntaxGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ private void FillTypeArguments(List<LuaExpressionSyntax> typeArguments, INamedTy
private string GetNamespaceMapName(INamespaceSymbol symbol, string original) {
if (symbol.IsFromCode()) {
var names = symbol.GetAllNamespaces().Select(i => namespaceRefactorNames_.GetOrDefault(i, i.Name));
return string.Join('.', names);
return string.Join(".", names);
} else {
return XmlMetaProvider.GetNamespaceMapName(symbol, original);
}
Expand Down
4 changes: 2 additions & 2 deletions test/fibonacci/cmd.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
set dir=../../CSharp.lua/bin/Debug/netcoreapp2.0/
dotnet "%dir%CSharp.lua.dll" -s src -d out
set dir=../../CSharp.lua.Launcher/bin/Debug/netcoreapp2.0/
dotnet "%dir%CSharp.lua.Launcher.dll" -s src -d out
"../__bin/lua5.1/lua" launcher.lua
4 changes: 2 additions & 2 deletions test/self-compiling/self.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set dir=../../CSharp.lua/bin/Debug/netcoreapp2.0/
set dir=../../CSharp.lua.Launcher/bin/Debug/netcoreapp2.0/
set lib=lib/
set obj="../../CSharp.lua/obj"
if exist %obj% rd /s /q %obj%
dotnet "%dir%CSharp.lua.dll" -s ../../CSharp.lua/ -d selfout -l %lib%Microsoft.CodeAnalysis.CSharp.dll;%lib%Microsoft.CodeAnalysis.dll
dotnet "%dir%CSharp.lua.Launcher.dll" -s ../../CSharp.lua/ -d selfout -l %lib%Microsoft.CodeAnalysis.CSharp.dll;%lib%Microsoft.CodeAnalysis.dll
2 changes: 1 addition & 1 deletion test/self-compiling/selfout/LuaSyntaxGenerator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ System.namespace("CSharpLua", function (namespace)
local names = Linq.Select(CSharpLua.Utility.GetAllNamespaces(symbol), function (i)
return CSharpLua.Utility.GetOrDefault1(this.namespaceRefactorNames_, i, i:getName(), MicrosoftCodeAnalysis.INamespaceSymbol, System.String)
end, System.String)
return System.String.Join(46 --[['.']], names, System.String)
return System.String.Join(".", names)
else
return this.XmlMetaProvider:GetNamespaceMapName(symbol, original)
end
Expand Down
14 changes: 12 additions & 2 deletions test/self-compiling/selfout/LuaSyntaxNodeTransfor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4199,8 +4199,18 @@ System.namespace("CSharpLua", function (namespace)
end
else
local memberAccess = CSharpLuaLuaAst.LuaMemberAccessExpressionSyntax(temp, CSharpLuaLuaAst.LuaIdentifierNameSyntax.Add, true)
local value = System.cast(CSharpLuaLuaAst.LuaExpressionSyntax, expression:Accept(this, CSharpLuaLuaAst.LuaSyntaxNode))
function_:AddStatement1(CSharpLuaLuaAst.LuaInvocationExpressionSyntax:new(2, memberAccess, value))
local invocation = CSharpLuaLuaAst.LuaInvocationExpressionSyntax:new(1, memberAccess)
if MicrosoftCodeAnalysis.CSharpExtensions.IsKind(expression, 8648 --[[SyntaxKind.ComplexElementInitializerExpression]]) then
local initializer = System.cast(MicrosoftCodeAnalysisCSharpSyntax.InitializerExpressionSyntax, expression)
for _, expressionNode in System.each(initializer:getExpressions()) do
local argumnet = System.cast(CSharpLuaLuaAst.LuaExpressionSyntax, expressionNode:Accept(this, CSharpLuaLuaAst.LuaSyntaxNode))
invocation:AddArgument(argumnet)
end
else
local value = System.cast(CSharpLuaLuaAst.LuaExpressionSyntax, expression:Accept(this, CSharpLuaLuaAst.LuaSyntaxNode))
invocation:AddArgument(value)
end
function_:AddStatement1(invocation)
end
end

Expand Down

0 comments on commit 41e47f1

Please sign in to comment.