Example #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));
        }
Example #2
0
 static TypeTraits()
 {
     Check           = TypeTraitsBase.GetDefaultCheck(IsValueType, type);
     GetLuaReference = TypeTraitsBase.GetLuaReference(type);
 }