public bool CheckTransform(IntPtr L, int pos) { LuaTypes luaType = LuaDLL.lua_type(L, pos); switch (luaType) { case LuaTypes.LUA_TNIL: return(true); case LuaTypes.LUA_TUSERDATA: int udata = LuaDLL.tolua_rawnetobj(L, pos); if (udata != -1) { Il2cppType il = il2cpp; ObjectTranslator translator = ObjectTranslator.Get(L); Type type = translator.CheckOutNodeType(udata); return(type == null ? udata == 1 : type == il.TypeOfTransform || il.TypeOfTransform.IsAssignableFrom(type)); } return(false); default: return(false); } }
public static bool IsNumberType(Type t) { if (t.IsPrimitive) { Il2cppType il = il2cpp; if (t == il.TypeOfBool || t == il.TypeOfIntPtr || t == il.TypeOfUIntPtr) { return(false); } return(true); } return(false); }
public static bool CheckType(IntPtr L, Type type, int pos) { Il2cppType il = il2cpp; //默认都可以转 object if (type == il.TypeOfObject) { return(true); } Type t = GetNullableType(type); LuaTypes luaType = LuaDLL.lua_type(L, pos); switch (luaType) { case LuaTypes.LUA_TNUMBER: return(IsNumberType(t)); case LuaTypes.LUA_TSTRING: return(t == il.TypeOfString || t == il.TypeOfByteArray || t == il.TypeOfCharArray || t == il.TypeOfLuaByteBuffer); case LuaTypes.LUA_TUSERDATA: return(IsMatchUserData(L, t, pos)); case LuaTypes.LUA_TBOOLEAN: return(t == il.TypeOfBool); case LuaTypes.LUA_TFUNCTION: return(t == il.TypeOfLuaFunction); case LuaTypes.LUA_TTABLE: return(IsUserTable(t, L, pos)); case LuaTypes.LUA_TLIGHTUSERDATA: return(t == il.TypeOfIntPtr || t == il.TypeOfUIntPtr); case LuaTypes.LUA_TNIL: return(IsNilType(type)); default: break; } throw new LuaException("undefined type to check" + LuaDLL.luaL_typename(L, pos)); }
static TypeChecker() { Il2cppType il = il2cpp; LuaValueTypeMap[LuaValueType.None] = null; LuaValueTypeMap[LuaValueType.Vector3] = il.TypeOfVector3; LuaValueTypeMap[LuaValueType.Quaternion] = il.TypeOfQuaternion; LuaValueTypeMap[LuaValueType.Vector2] = il.TypeOfVector2; LuaValueTypeMap[LuaValueType.Color] = il.TypeOfColor; LuaValueTypeMap[LuaValueType.Vector4] = il.TypeOfVector4; LuaValueTypeMap[LuaValueType.Ray] = il.TypeOfRay; LuaValueTypeMap[LuaValueType.Bounds] = il.TypeOfBounds; LuaValueTypeMap[LuaValueType.Touch] = il.TypeOfTouch; LuaValueTypeMap[LuaValueType.LayerMask] = il.TypeOfLayerMask; LuaValueTypeMap[LuaValueType.RaycastHit] = il.TypeOfRaycastHit; LuaValueTypeMap[LuaValueType.Int64] = il.TypeOfLong; LuaValueTypeMap[LuaValueType.UInt64] = il.TypeOfULong; }
static bool IsMatchUserData(IntPtr L, Type t, int pos) { Il2cppType il = il2cpp; if (t == il.TypeOfLong) { return(LuaDLL.tolua_getvaluetype(L, pos) == LuaValueType.Int64); } else if (t == il.TypeOfULong) { return(LuaDLL.tolua_getvaluetype(L, pos) == LuaValueType.UInt64); } object obj = null; int udata = LuaDLL.tolua_rawnetobj(L, pos); if (udata != -1) { ObjectTranslator translator = ObjectTranslator.Get(L); obj = translator.GetObject(udata); if (obj != null) { Type objType = obj.GetType(); if (t == objType || t.IsAssignableFrom(objType)) { return(true); } } else { return(!t.IsValueType); } } return(false); }
static bool IsMatchUserData(IntPtr L, Type t, int pos) { Il2cppType il = il2cpp; if (t == il.TypeOfLong) { return(LuaDLL.tolua_getvaluetype(L, pos) == LuaValueType.Int64); } else if (t == il.TypeOfULong) { return(LuaDLL.tolua_getvaluetype(L, pos) == LuaValueType.UInt64); } int udata = LuaDLL.tolua_rawnetobj(L, pos); if (udata != -1) { ObjectTranslator translator = ObjectTranslator.Get(L); Type eleType = translator.CheckOutNodeType(udata); return(eleType == null ? udata == 1 : eleType == t || t.IsAssignableFrom(eleType)); } return(false); }
public static string GetPrimitiveStr(Type t) { Il2cppType il = il2cpp; if (t == il.TypeOfFloat) { return("float"); } else if (t == il.TypeOfString) { return("string"); } else if (t == il.TypeOfInt) { return("int"); } else if (t == il.TypeOfDouble) { return("double"); } else if (t == il.TypeOfBool) { return("bool"); } else if (t == il.TypeOfUInt) { return("uint"); } else if (t == il.TypeOfSByte) { return("sbyte"); } else if (t == il.TypeOfByte) { return("byte"); } else if (t == il.TypeOfShort) { return("short"); } else if (t == il.TypeOfUShort) { return("ushort"); } else if (t == il.TypeOfChar) { return("char"); } else if (t == il.TypeOfLong) { return("long"); } else if (t == il.TypeOfULong) { return("ulong"); } else if (t == il.TypeOfDecimal) { return("decimal"); } else if (t == il.TypeOfObject) { return("object"); } else { return(t.ToString()); } }