Skip to content

Commit e183a9b

Browse files
authored
allow custom checker (#857)
1 parent d7150f3 commit e183a9b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Assets/XLua/Src/ObjectCasters.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ public ObjectCheck genNullableChecker(ObjectCheck oc)
191191
};
192192
}
193193

194+
public void AddChecker(Type type, ObjectCheck oc)
195+
{
196+
checkersMap[type] = oc;
197+
}
198+
194199
public ObjectCheck GetChecker(Type type)
195200
{
196201
if (type.IsByRef) type = type.GetElementType();

Assets/XLua/Src/ObjectTranslator.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,7 @@ bool tryGetGetFuncByType<T>(Type type, out T func) where T : class
16061606
}
16071607
}
16081608

1609-
1609+
public delegate bool CheckFunc<T>(RealStatePtr L, int idx);
16101610
public delegate void GetFunc<T>(RealStatePtr L, int idx, out T val);
16111611

16121612
public void RegisterPushAndGetAndUpdate<T>(Action<RealStatePtr, T> push, GetFunc<T> get, Action<RealStatePtr, int, T> update)
@@ -1640,6 +1640,14 @@ public void RegisterPushAndGetAndUpdate<T>(Action<RealStatePtr, T> push, GetFunc
16401640
);
16411641
}
16421642

1643+
public void RegisterChecker<T>(CheckFunc<T> check)
1644+
{
1645+
objectCheckers.AddChecker(typeof(T), (L, idx) =>
1646+
{
1647+
return check(L, idx);
1648+
});
1649+
}
1650+
16431651
public void RegisterCaster<T>(GetFunc<T> get)
16441652
{
16451653
objectCasters.AddCaster(typeof(T), (L, idx, o) =>

0 commit comments

Comments
 (0)