Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Tencent/xLua
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed Aug 13, 2019
2 parents c9aa552 + 0f34d89 commit 0d7c20e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Assets/XLua/Doc/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ il2cpp默认会对诸如引擎、c#系统api,第三方dll等等进行代码剪

编译链接的是:unity安装目录\Editor\Data\MonoBleedingEdge\lib\mono\4.7.1-api\mscorlib.dll

解决办法:2.1.14支持外部mono环境,安装个Unity2017,然后把Unity2017安装目录下的MonoBleedingEdge目录拷贝到工程目录下的Tools目录下即可
解决办法:用黑名单排除报错方法即可。不过2019年8月6号以前的版本的黑名单配置对泛型不友好,要一个个泛型实例的配置(比如,Dictionary<int, int>和Dictionary<float, int>要分别配置),而目前发现该问题主要出在泛型Dictionary上。可以更新到2019年8月6号之后的版本,该版本支持配置一个过滤器对泛型方法过滤。这里有对unity 2018的Dictionary的[针对性配置](https://github.com/Tencent/xLua/blob/master/Assets/XLua/Editor/ExampleConfig.cs#L277),直接拷贝使用,如果碰到其它泛型也有多出来的方法,参考Dictionary进行配置

## Plugins源码在哪里可以找到,怎么使用?

Expand Down
31 changes: 31 additions & 0 deletions Assets/XLua/Editor/ExampleConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,35 @@ public static class ExampleConfig
new List<string>(){"System.IO.DirectoryInfo", "Create", "System.Security.AccessControl.DirectorySecurity"},
new List<string>(){"UnityEngine.MonoBehaviour", "runInEditMode"},
};

#if UNITY_2018_1_OR_NEWER
[BlackList]
public static Func<MemberInfo, bool> MethodFilter = (memberInfo) =>
{
if (memberInfo.DeclaringType.IsGenericType && memberInfo.DeclaringType.GetGenericTypeDefinition() == typeof(Dictionary<,>))
{
if (memberInfo.MemberType == MemberTypes.Constructor)
{
ConstructorInfo constructorInfo = memberInfo as ConstructorInfo;
var parameterInfos = constructorInfo.GetParameters();
if (parameterInfos.Length > 0)
{
if (typeof(System.Collections.IEnumerable).IsAssignableFrom(parameterInfos[0].ParameterType))
{
return true;
}
}
}
else if (memberInfo.MemberType == MemberTypes.Method)
{
var methodInfo = memberInfo as MethodInfo;
if (methodInfo.Name == "TryAdd" || methodInfo.Name == "Remove" && methodInfo.GetParameters().Length == 2)
{
return true;
}
}
}
return false;
};
#endif
}
24 changes: 24 additions & 0 deletions Assets/XLua/Src/Editor/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,14 @@ static bool isMemberInBlackList(MemberInfo mb)
if (mb is FieldInfo && (mb as FieldInfo).FieldType.IsPointer) return true;
if (mb is PropertyInfo && (mb as PropertyInfo).PropertyType.IsPointer) return true;

foreach(var filter in memberFilters)
{
if (filter(mb))
{
return true;
}
}

foreach (var exclude in BlackList)
{
if (mb.DeclaringType.ToString() == exclude[0] && mb.Name == exclude[1])
Expand All @@ -546,6 +554,14 @@ static bool isMethodInBlackList(MethodBase mb)
if (mb.GetParameters().Any(pInfo => pInfo.ParameterType.IsPointer)) return true;
if (mb is MethodInfo && (mb as MethodInfo).ReturnType.IsPointer) return false;

foreach (var filter in memberFilters)
{
if (filter(mb))
{
return true;
}
}

foreach (var exclude in BlackList)
{
if (mb.DeclaringType.ToString() == exclude[0] && mb.Name == exclude[1])
Expand Down Expand Up @@ -1270,6 +1286,8 @@ public static void GenPackUnpack(IEnumerable<Type> types, string save_path)

public static List<string> assemblyList = null;

public static List<Func<MemberInfo, bool>> memberFilters = null;

static void AddToList(List<Type> list, Func<object> get, object attr)
{
object obj = get();
Expand Down Expand Up @@ -1382,6 +1400,10 @@ static void MergeCfg(MemberInfo test, Type cfg_type, Func<object> get_cfg)
{
BlackList.AddRange(get_cfg() as List<List<string>>);
}
if (isDefined(test, typeof(BlackListAttribute)) && typeof(Func<MemberInfo, bool>).IsAssignableFrom(cfg_type))
{
memberFilters.Add(get_cfg() as Func<MemberInfo, bool>);
}

if (isDefined(test, typeof(AdditionalPropertiesAttribute))
&& (typeof(Dictionary<Type, List<string>>)).IsAssignableFrom(cfg_type))
Expand Down Expand Up @@ -1456,6 +1478,8 @@ public static void GetGenConfig(IEnumerable<Type> check_types)
#else
assemblyList = new List<string>();
#endif
memberFilters = new List<Func<MemberInfo, bool>>();

foreach (var t in check_types)
{
MergeCfg(t, null, () => t);
Expand Down

0 comments on commit 0d7c20e

Please sign in to comment.