Skip to content

Commit

Permalink
allow custom checker (#857)
Browse files Browse the repository at this point in the history
  • Loading branch information
Domain authored Dec 6, 2021
1 parent d7150f3 commit e183a9b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Assets/XLua/Src/ObjectCasters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ public ObjectCheck genNullableChecker(ObjectCheck oc)
};
}

public void AddChecker(Type type, ObjectCheck oc)
{
checkersMap[type] = oc;
}

public ObjectCheck GetChecker(Type type)
{
if (type.IsByRef) type = type.GetElementType();
Expand Down
10 changes: 9 additions & 1 deletion Assets/XLua/Src/ObjectTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,7 @@ bool tryGetGetFuncByType<T>(Type type, out T func) where T : class
}
}


public delegate bool CheckFunc<T>(RealStatePtr L, int idx);
public delegate void GetFunc<T>(RealStatePtr L, int idx, out T val);

public void RegisterPushAndGetAndUpdate<T>(Action<RealStatePtr, T> push, GetFunc<T> get, Action<RealStatePtr, int, T> update)
Expand Down Expand Up @@ -1640,6 +1640,14 @@ public void RegisterPushAndGetAndUpdate<T>(Action<RealStatePtr, T> push, GetFunc
);
}

public void RegisterChecker<T>(CheckFunc<T> check)
{
objectCheckers.AddChecker(typeof(T), (L, idx) =>
{
return check(L, idx);
});
}

public void RegisterCaster<T>(GetFunc<T> get)
{
objectCasters.AddCaster(typeof(T), (L, idx, o) =>
Expand Down

0 comments on commit e183a9b

Please sign in to comment.