Beispiel #1
0
        static T DefaultCheck(IntPtr L, int stackPos)
        {
            int udata = LuaDLL.tolua_rawnetobj(L, stackPos);

            if (udata != -1)
            {
                ObjectTranslator translator = ObjectTranslator.Get(L);
                Type             eleType    = translator.CheckOutNodeType(udata);
                if (eleType != null)
                {
                    bool bValid = eleType == TypeTraits <T> .type || TypeTraits <T> .type.IsAssignableFrom(eleType);

                    if (bValid)
                    {
                        return(translator.GetObject <T>(udata));
                    }
                    else
                    {
                        LuaDLL.luaL_argerror(L, stackPos, string.Format("{0} expected, got {1}", TypeTraits <T> .GetTypeName(), eleType != null ? eleType.FullName : "null"));
                    }
                }
                else if (udata == 1)
                {
                    return(default(T));
                }
            }
            else if (TypeTraitsBase.IsNilType(TypeTraits <T> .IsValueType, TypeTraits <T> .type) && LuaDLL.lua_isnil(L, stackPos))
            {
                return(default(T));
            }

            LuaDLL.luaL_typerror(L, stackPos, TypeTraits <T> .GetTypeName());
            return(default(T));
        }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
        static public bool CheckDelegateType <T>(IntPtr L, int pos) //where T : Delegate
        {
            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)
                {
                    Type             t          = TypeTraits <T> .type;
                    ObjectTranslator translator = ObjectTranslator.Get(L);
                    Type             eleType    = translator.CheckOutNodeType(udata);
                    return(eleType == null ? udata == 1 : eleType == t || t.IsAssignableFrom(eleType));
                }
                return(false);

            default:
                return(false);
            }
        }
Beispiel #4
0
        static bool IsUserData(IntPtr L, int pos, Type type)
        {
            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 == type || type.IsAssignableFrom(eleType));
            }

            return(false);
        }
Beispiel #5
0
        bool CheckClassType(Type t, IntPtr L, int pos)
        {
            int udata = LuaDLL.tolua_rawnetobj(L, pos);

            if (udata != -1)
            {
                ObjectTranslator translator = ObjectTranslator.Get(L);
                Type             type       = translator.CheckOutNodeType(udata);
                return(type == null ? udata == 1 : type == t);
            }

            return(false);
        }
Beispiel #6
0
        static public bool CheckEnumType(Type type, IntPtr L, int pos)
        {
            if (LuaDLL.lua_type(L, pos) == LuaTypes.LUA_TUSERDATA)
            {
                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 == type);
                }
            }

            return(false);
        }
Beispiel #7
0
        ////换模板
        static public bool CheckDelegateType(Type type, 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)
                {
                    ObjectTranslator translator = ObjectTranslator.Get(L);
                    Type             eleType    = translator.CheckOutNodeType(udata);
                    return(eleType == null ? udata == 1 : type == eleType);
                }
                return(false);

            default:
                return(false);
            }
        }
Beispiel #8
0
        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);
        }