Skip to content
New issue

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

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

Already on GitHub? # to your account

Allow access container whose key is string #965

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions Assets/XLua/Src/CodeEmit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ public Type EmitTypeWrap(Type toBeWrap)
.Where(m => !m.IsSpecialName
|| (
((m.Name == "get_Item" && m.GetParameters().Length == 1) || (m.Name == "set_Item" && m.GetParameters().Length == 2))
&& m.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string))
&& m.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string)) && toBeWrap.GetCustomAttribute<LuaIndexerAttribute>() == null
)
).GroupBy(m => m.Name).ToList();
var supportOperators = toBeWrap.GetMethods(staticFlag)
Expand Down Expand Up @@ -1293,7 +1293,7 @@ public Type EmitTypeWrap(Type toBeWrap)
{
if (prop.GetIndexParameters().Length > 0)
{
if (!prop.GetIndexParameters()[0].ParameterType.IsAssignableFrom(typeof(string)))
if (!prop.GetIndexParameters()[0].ParameterType.IsAssignableFrom(typeof(string)) || toBeWrap.GetCustomAttribute<LuaIndexerAttribute>() != null)
{
itemGetter.Add(getter);
}
Expand All @@ -1309,7 +1309,7 @@ public Type EmitTypeWrap(Type toBeWrap)
{
if (prop.GetIndexParameters().Length > 0)
{
if (!prop.GetIndexParameters()[0].ParameterType.IsAssignableFrom(typeof(string)))
if (!prop.GetIndexParameters()[0].ParameterType.IsAssignableFrom(typeof(string)) || toBeWrap.GetCustomAttribute<LuaIndexerAttribute>() != null)
{
itemSetter.Add(setter);
}
Expand Down
12 changes: 7 additions & 5 deletions Assets/XLua/Src/Editor/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ static void getClassInfo(Type type, LuaTable parameters)
.Where(method => !method.IsSpecialName
|| (
((method.Name == "get_Item" && method.GetParameters().Length == 1) || (method.Name == "set_Item" && method.GetParameters().Length == 2))
&& method.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string))
&& method.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string)) && type.GetCustomAttribute<LuaIndexerAttribute>() == null
)
)
.Concat(extension_methods)
Expand Down Expand Up @@ -380,12 +380,14 @@ static void getClassInfo(Type type, LuaTable parameters)
var indexers = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).Where(prop => prop.GetIndexParameters().Length > 0);

parameters.Set("indexers", indexers.Where(prop => prop.CanRead && (prop.GetGetMethod() != null)).Select(prop => prop.GetGetMethod())
.Where(method => method.GetParameters().Length == 1 && !method.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string)))
.ToList());
.Where(method => method.GetParameters().Length == 1 && (!method.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string))
|| type.GetCustomAttribute<LuaIndexerAttribute>() != null))
.OrderBy(t => t.Name).ToList());

parameters.Set("newindexers", indexers.Where(prop => prop.CanWrite && (prop.GetSetMethod() != null)).Select(prop => prop.GetSetMethod())
.Where(method => method.GetParameters().Length == 2 && !method.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string)))
.ToList());
.Where(method => method.GetParameters().Length == 2 && (!method.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string))
|| type.GetCustomAttribute<LuaIndexerAttribute>() != null))
.OrderBy(t => t.Name).ToList());

parameters.Set("events", type.GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.DeclaredOnly).Where(e => !isObsolete(e) && !isMemberInBlackList(e))
.Where(ev=> ev.GetAddMethod() != null || ev.GetRemoveMethod() != null)
Expand Down
5 changes: 5 additions & 0 deletions Assets/XLua/Src/GenAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ internal class HotfixDelegateAttribute : Attribute
{
}

public class LuaIndexerAttribute : Attribute
{

}

#if !XLUA_GENERAL
public static class SysGenConfig
{
Expand Down
2 changes: 1 addition & 1 deletion Assets/XLua/Src/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ static void makeReflectionWrap(RealStatePtr L, Type type, int cls_field, int cls
//indexer
if (method.IsSpecialName && ((method.Name == "get_Item" && method.GetParameters().Length == 1) || (method.Name == "set_Item" && method.GetParameters().Length == 2)))
{
if (!method.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string)))
if (!method.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string)) || type.GetCustomAttribute<LuaIndexerAttribute>() != null)
{
continue;
}
Expand Down