Skip to content

Commit

Permalink
fix #311
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed Mar 14, 2018
1 parent d011ee4 commit e9b8722
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion Assets/XLua/Src/Editor/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ static Generator()
});
}

static bool IsOverride(MethodBase method)
{
var m = method as MethodInfo;
return m != null && !m.IsConstructor && m.IsVirtual && (m.GetBaseDefinition().DeclaringType != m.DeclaringType);
}

static int OverloadCosting(MethodBase mi)
{
int costing = 0;
Expand Down Expand Up @@ -310,6 +316,8 @@ static void getClassInfo(Type type, LuaTable parameters)
}
parameters.Set("namespaces", extension_methods_namespace.Distinct().ToList());

List<LazyMemberInfo> lazyMemberInfos = new List<LazyMemberInfo>();

//warnning: filter all method start with "op_" "add_" "remove_" may filter some ordinary method
parameters.Set("methods", type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.DeclaredOnly)
.Where(method => !method.IsDefined(typeof (ExtensionAttribute), false) || method.GetParameters()[0].ParameterType.IsInterface || method.DeclaringType != type)
Expand All @@ -321,12 +329,18 @@ static void getClassInfo(Type type, LuaTable parameters)
{
var overloads = new List<MethodBase>();
List<int> def_vals = new List<int>();
bool isOverride = false;
foreach (var overload in v.Cast<MethodBase>().OrderBy(mb => OverloadCosting(mb)))
{
int def_count = 0;
overloads.Add(overload);
def_vals.Add(def_count);

if (!isOverride)
{
isOverride = IsOverride(overload);
}

var ps = overload.GetParameters();
for (int i = ps.Length - 1; i >=0; i--)
{
Expand All @@ -343,6 +357,18 @@ static void getClassInfo(Type type, LuaTable parameters)
}
}
}
#if HOTFIX_ENABLE
if (isOverride)
{
lazyMemberInfos.Add(new LazyMemberInfo
{
Index = "METHOD_IDX",
Name = "<>xLuaBaseProxy_" + k,
MemberType = "LazyMemberTypes.Method",
IsStatic = "false"
});
}
#endif
return new {
Name = k,
IsStatic = overloads[0].IsStatic && (!overloads[0].IsDefined(typeof(ExtensionAttribute), false) || overloads[0].GetParameters()[0].ParameterType.IsInterface),
Expand Down Expand Up @@ -386,7 +412,7 @@ static void getClassInfo(Type type, LuaTable parameters)
.Select(ev => new { IsStatic = ev.GetAddMethod() != null? ev.GetAddMethod().IsStatic: ev.GetRemoveMethod().IsStatic, ev.Name,
CanSet = false, CanAdd = ev.GetRemoveMethod() != null, CanRemove = ev.GetRemoveMethod() != null, Type = ev.EventHandlerType})
.ToList());
List<LazyMemberInfo> lazyMemberInfos = new List<LazyMemberInfo>();

parameters.Set("lazymembers", lazyMemberInfos);
foreach (var member in type.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.DeclaredOnly)
.Where(m => IsDoNotGen(type, m.Name))
Expand Down

0 comments on commit e9b8722

Please sign in to comment.