示例#1
0
        public static bool MatchType(IntPtr ptr, int p, LuaTypes lt, Type t)
        {
            if (t == typeof(object))
            {
                return(true);
            }
            else if (t == typeof(Type) && IsTypeTable(ptr, p))
            {
                return(true);
            }
            else if (t == typeof(char[]) || t == typeof(byte[]))
            {
                return(lt == LuaTypes.TYPE_STRING);
            }

            switch (lt)
            {
            case LuaTypes.TYPE_NIL:
                return(!t.IsValueType && !t.IsPrimitive);

            case LuaTypes.TYPE_NUMBER:
#if LUA_5_3
                if (LuaNativeMethods.lua_isinteger(ptr, p) > 0)
                {
                    return((t.IsPrimitive && t != typeof(float) && t != typeof(double)) || t.IsEnum);
                }
                else
                {
                    return(t == typeof(float) || t == typeof(double));
                }
#else
                return(t.IsPrimitive || t.IsEnum);
#endif
            case LuaTypes.TYPE_USERDATA:
                object o  = CheckObj(ptr, p);
                Type   ot = o.GetType();
                return(ot == t || ot.IsSubclassOf(t) || t.IsAssignableFrom(ot));

            case LuaTypes.TYPE_STRING:
                return(t == typeof(string));

            case LuaTypes.TYPE_BOOLEAN:
                return(t == typeof(bool));

            case LuaTypes.TYPE_TABLE:
                if (t == typeof(LuaTable) || t.IsArray)
                {
                    return(true);
                }
                else if (t.IsValueType)
                {
                    return(true);    // luaTypeCheck(ptr, p, t.Name);
                }
                else if (LuaNativeMethods.luaS_subclassof(ptr, p, t.Name) == 1)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }

            case LuaTypes.TYPE_FUNCTION:
                return(t == typeof(LuaFunction) || t.BaseType == typeof(MulticastDelegate));

            case LuaTypes.TYPE_THREAD:
                return(t == typeof(LuaThread));
            }

            return(false);
        }