Пример #1
0
        static public Delegate Create(LuaFunction func, LuaTable self)
        {
#if UNITY_EDITOR
            if (_Create == null)
            {
                throw new LuaException(string.Format("Delegate {0} not register", TypeTraits <T> .GetTypeName()));
            }
#endif
            if (func != null)
            {
                LuaState    state  = func.GetLuaState();
                LuaDelegate target = state.GetLuaDelegate(func, self);

                if (target != null)
                {
                    return(Delegate.CreateDelegate(typeof(T), target, target.method));
                }
                else
                {
                    Delegate d = _Create(func, self, true);
                    target = d.Target as LuaDelegate;
                    state.AddLuaDelegate(target, func, self);
                    return(d);
                }
            }

            return(_Create(null, null, true));
        }
Пример #2
0
        static T DefaultCheck(IntPtr L, int stackPos)
        {
            int udata = LuaDLL.tolua_rawnetobj(L, stackPos);

            if (udata != -1)
            {
                ObjectTranslator translator = ObjectTranslator.Get(L);
                object           obj        = translator.GetObject(udata);

                if (obj != null)
                {
                    if (obj is T)
                    {
                        return((T)obj);
                    }

                    LuaDLL.luaL_argerror(L, stackPos, string.Format("{0} expected, got {1}", TypeTraits <T> .GetTypeName(), obj.GetType().FullName));
                }

                if (!TypeTraits <T> .IsValueType)
                {
                    return(default(T));
                }
            }
            else if (LuaDLL.lua_isnil(L, stackPos) && !TypeTraits <T> .IsValueType)
            {
                return(default(T));
            }

            LuaDLL.luaL_typerror(L, stackPos, TypeTraits <T> .GetTypeName());
            return(default(T));
        }
Пример #3
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));
        }