Skip to content

Commit

Permalink
1、生成代码工具改进
Browse files Browse the repository at this point in the history
2、general工程加上GenericDelegateBridge.cs的引用
  • Loading branch information
chexiongsheng committed Nov 15, 2018
1 parent b29ab3e commit ea673f0
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 39 deletions.
117 changes: 83 additions & 34 deletions Assets/XLua/Src/Editor/Generator.cs

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions Assets/XLua/Src/Editor/Template/TemplateCommon.lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,17 @@ end

local delegateType = typeof(CS.System.Delegate)
local ExtensionAttribute = typeof(CS.System.Runtime.CompilerServices.ExtensionAttribute)

function IsExtensionMethod(method)
return method:IsDefined(ExtensionAttribute, false)
end

function IsDelegate(t)
return delegateType:IsAssignableFrom(t)
end

function MethodParameters(method)
if not method:IsDefined(ExtensionAttribute, false) then
if not IsExtensionMethod(method) then
return method:GetParameters()
else
local parameters = method:GetParameters()
Expand Down Expand Up @@ -304,7 +313,7 @@ function GetCasterStatement(t, idx, var_name, need_declare, is_v_params)
return statement .. "translator.GetParams<" .. CsFullTypeName(t:GetElementType()).. ">" .. "(L, ".. idx ..")"
elseif typedCaster[testname] then
return statement .. "(" .. CsFullTypeName(t) .. ")" ..typedCaster[testname] .. "(L, ".. idx ..")"
elseif delegateType:IsAssignableFrom(t) then
elseif IsDelegate(t) then
return statement .. "translator.GetDelegate<" .. CsFullTypeName(t).. ">" .. "(L, ".. idx ..")"
elseif fixCaster[testname] then
return statement .. fixCaster[testname] .. "(L, ".. idx ..")"
Expand Down
25 changes: 24 additions & 1 deletion General/Src/XLuaGenerate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Reflection;
using CSObjectWrapEditor;
using System.IO;
using System.Collections.Generic;

namespace XLua
{
Expand All @@ -21,7 +22,29 @@ public static void Main(string[] args)
return;
}

var assembly = Assembly.LoadFile(Path.GetFullPath(args[0]));
if (args.Length > 1)
{
GeneratorConfig.common_path = args[1];
}

if (args.Length > 2)
{
List<string> search_paths = args.Skip(2).ToList();
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler((object sender, ResolveEventArgs rea) =>
{
foreach (var search_path in search_paths)
{
string assemblyPath = Path.Combine(search_path, new AssemblyName(rea.Name).Name + ".dll");
if (File.Exists(assemblyPath))
{
return Assembly.Load(File.ReadAllBytes(assemblyPath));
}
}
return null;
});
}

var assembly = Assembly.Load(File.ReadAllBytes(Path.GetFullPath(args[0])));
Generator.GenAll(new XLuaTemplates()
{
LuaClassWrap = new XLuaTemplate()
Expand Down
1 change: 1 addition & 0 deletions General/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ files
defines
{
"XLUA_GENERAL",
"XLUA_ALL_OBSOLETE",
}

links
Expand Down
3 changes: 3 additions & 0 deletions General/vs2013/XLua.Mini.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<Compile Include="..\..\Assets\XLua\Src\GenAttributes.cs">
<Link>Assets\XLua\Src\GenAttributes.cs</Link>
</Compile>
<Compile Include="..\..\Assets\XLua\Src\GenericDelegateBridge.cs">
<Link>Assets\XLua\Src\GenericDelegateBridge.cs</Link>
</Compile>
<Compile Include="..\..\Assets\XLua\Src\InternalGlobals.cs">
<Link>Assets\XLua\Src\InternalGlobals.cs</Link>
</Compile>
Expand Down
4 changes: 2 additions & 2 deletions General/vs2013/XLuaGenerate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<OutputPath>..\Tools\</OutputPath>
<BaseIntermediateOutputPath>obj\Any CPU\Debug\XLuaGenerate\</BaseIntermediateOutputPath>
<IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>
<DefineConstants>_DEBUG;DEBUG;TRACE;;XLUA_GENERAL</DefineConstants>
<DefineConstants>_DEBUG;DEBUG;TRACE;;XLUA_GENERAL;XLUA_ALL_OBSOLETE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
Expand All @@ -31,7 +31,7 @@
<OutputPath>..\Tools\</OutputPath>
<BaseIntermediateOutputPath>obj\Any CPU\Release\XLuaGenerate\</BaseIntermediateOutputPath>
<IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>
<DefineConstants>;XLUA_GENERAL</DefineConstants>
<DefineConstants>;XLUA_GENERAL;XLUA_ALL_OBSOLETE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
Expand Down
3 changes: 3 additions & 0 deletions General/vs2013/XLuaTestGenCode.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<Compile Include="..\..\Assets\XLua\Src\GenAttributes.cs">
<Link>Assets\XLua\Src\GenAttributes.cs</Link>
</Compile>
<Compile Include="..\..\Assets\XLua\Src\GenericDelegateBridge.cs">
<Link>Assets\XLua\Src\GenericDelegateBridge.cs</Link>
</Compile>
<Compile Include="..\..\Assets\XLua\Src\InternalGlobals.cs">
<Link>Assets\XLua\Src\InternalGlobals.cs</Link>
</Compile>
Expand Down
3 changes: 3 additions & 0 deletions General/vs2013/XLuaUnitTestGenCode.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<Compile Include="..\..\Assets\XLua\Src\GenAttributes.cs">
<Link>Assets\XLua\Src\GenAttributes.cs</Link>
</Compile>
<Compile Include="..\..\Assets\XLua\Src\GenericDelegateBridge.cs">
<Link>Assets\XLua\Src\GenericDelegateBridge.cs</Link>
</Compile>
<Compile Include="..\..\Assets\XLua\Src\InternalGlobals.cs">
<Link>Assets\XLua\Src\InternalGlobals.cs</Link>
</Compile>
Expand Down

0 comments on commit ea673f0

Please sign in to comment.