Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复NativeArray类型导出错误问题 #239

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
70 changes: 46 additions & 24 deletions Assets/ToLua/Editor/ToLuaExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,16 +293,32 @@ public string GenParamTypes(int offset = 0)
continue;
}

if (args[i].ParameterType.IsByRef && (args[i].Attributes & ParameterAttributes.Out) != ParameterAttributes.None)
if (args[i].Attributes != ParameterAttributes.Out)
{
Type genericClass = typeof(LuaOut<>);
Type t = genericClass.MakeGenericType(args[i].ParameterType.GetElementType());
list.Add(t);
list.Add(GetGenericBaseType(method, args[i].ParameterType));
}
else
{
list.Add(GetGenericBaseType(method, args[i].ParameterType));
}
Type genericClass = typeof(LuaOut<>);

// by wing
//
var tp = args[i].ParameterType.GetElementType();

if (tp == null)
{
tp = args[i].ParameterType.GenericTypeArguments[0];
}
if (tp != null)
{
Type t = genericClass.MakeGenericType(tp);
list.Add(t);
}
else
{

}
}
}

for (int i = offset; i < list.Count - 1; i++)
Expand Down Expand Up @@ -465,7 +481,7 @@ public int ProcessParams(int tab, bool beConstruct, int checkTypePos)
{
ParameterInfo param = paramInfos[j];
string arg = "arg" + j;
bool beOutArg = param.ParameterType.IsByRef && ((param.Attributes & ParameterAttributes.Out) != ParameterAttributes.None);
bool beOutArg = param.Attributes == ParameterAttributes.Out;
bool beParams = IsParams(param);
Type t = GetGenericBaseType(method, param.ParameterType);
ProcessArg(t, head, arg, offset + j, j >= checkTypePos, beParams, beOutArg);
Expand All @@ -475,14 +491,14 @@ public int ProcessParams(int tab, bool beConstruct, int checkTypePos)
{
ParameterInfo param = paramInfos[j];

if (!param.ParameterType.IsByRef || ((param.Attributes & ParameterAttributes.In) != ParameterAttributes.None))
if (!param.ParameterType.IsByRef)
{
sbArgs.Append("arg");
}
else
{
if ((param.Attributes & ParameterAttributes.Out) != ParameterAttributes.None)
{
if (param.Attributes == ParameterAttributes.Out)
{
sbArgs.Append("out arg");
}
else
Expand Down Expand Up @@ -2282,7 +2298,13 @@ static void ProcessArg(Type varType, string head, string arg, int stackPos, bool
string checkStr = beCheckTypes ? "To" : "Check";

if (beOutArg)
{
{
// by wing
if (varType.AssemblyQualifiedName.Contains("Unity.Collections.NativeArray"))
{
sb.AppendFormat("{0}{1} {2} = new {1}();\r\n", head, str, arg);
}
else
if (varType.IsValueType)
{
sb.AppendFormat("{0}{1} {2};\r\n", head, str, arg);
Expand Down Expand Up @@ -3054,16 +3076,16 @@ static string GenParamTypes(ParameterInfo[] p, MethodBase mb, int offset = 0)
continue;
}

if (p[i].ParameterType.IsByRef && (p[i].Attributes & ParameterAttributes.Out) != ParameterAttributes.None)
{
Type genericClass = typeof(LuaOut<>);
Type t = genericClass.MakeGenericType(p[i].ParameterType);
list.Add(t);
}
else
{
list.Add(GetGenericBaseType(mb, p[i].ParameterType));
}
if (p[i].Attributes != ParameterAttributes.Out)
{
list.Add(GetGenericBaseType(mb, p[i].ParameterType));
}
else
{
Type genericClass = typeof(LuaOut<>);
Type t = genericClass.MakeGenericType(p[i].ParameterType);
list.Add(t);
}
}

for (int i = offset; i < list.Count - 1; i++)
Expand Down Expand Up @@ -3572,7 +3594,7 @@ static void GenDelegateBody(StringBuilder sb, Type t, string head, bool hasSelf
{
sb.AppendFormat("{2}\tfunc.PushByteBuffer(param{1});\r\n", push, i, head);
}
else if ((pi[i].Attributes & ParameterAttributes.Out) == ParameterAttributes.None)
else if (pi[i].Attributes != ParameterAttributes.Out)
{
sb.AppendFormat("{2}\tfunc.{0}(param{1});\r\n", push, i, head);
}
Expand Down Expand Up @@ -3996,8 +4018,8 @@ static string GetDefaultDelegateBody(MethodInfo md)

for (int i = 0; i < pis.Length; i++)
{
if ((pis[i].Attributes & ParameterAttributes.Out) != ParameterAttributes.None)
{
if (pis[i].Attributes == ParameterAttributes.Out)
{
str += string.Format("\t\t\t\tparam{0} = {1};\r\n", i, GetReturnValue(pis[i].ParameterType.GetElementType()));
flag = true;
}
Expand Down