示例#1
0
        public static ImmutableArray <byte> EncodeAsImmutable(BaseLibrary record)
        {
            var writer = BebopWriter.Create();

            __EncodeInto(record, ref writer);
            return(writer.ToImmutableArray());
        }
        /// <summary>
        /// Loads a <see cref="BaseLibrary"/> into this Page
        /// </summary>
        /// <param name="lib"></param>
        /// <param name="args">Arguments to pass on the library's Initialize method</param>
        public void LoadLibrary(BaseLibrary lib, params object[] args)
        {
            foreach (var existing in libraries)
            {
                if (existing.GetType().Equals(lib.GetType()))
                {
                    return;
                }
            }

            try
            {
                lib.Initialize(args);
                lock (syncObj)
                {
                    foreach (var kv in lib.Handlers)
                    {
                        AddTriggerHandler(kv.Key, kv.Value);
                    }
                    libraries.Add(lib);
                }
                Logger.Debug <Page>($"Added library {lib.GetType().Name}");
            }
            catch (Exception ex)
            {
                Logger.Error <Page>($"Failed to initialize {lib.GetType().Name}");
            }
        }
示例#3
0
        public static byte[] Encode(BaseLibrary record)
        {
            var writer = BebopWriter.Create();

            __EncodeInto(record, ref writer);
            return(writer.ToArray());
        }
示例#4
0
        void SetupLibraries()
        {
            BaseLibrary   = new BaseLibrary(this);
            StringLibrary = new StringLibrary(this);

            Globals = new LuaTable();
            BaseLibrary.Setup(Globals);
            //StringLibrary.Setup(StringGlobals);
        }
示例#5
0
 internal static void __EncodeInto(BaseLibrary record, ref BebopWriter writer)
 {
     writer.WriteUInt32(unchecked ((uint)record.Songs.Count));
     foreach (var kv0 in record.Songs)
     {
         writer.WriteGuid(kv0.Key);
         Bebop.Codegen.Song.__EncodeInto(kv0.Value, ref writer);
     }
 }
示例#6
0
        public static object RelationalMetamethod(Context context, ExprType op, object left, object right)
        {
            if (left.GetType() != right.GetType())
            {
                return(false);
            }

            // There are no metamethods for 'a > b' and 'a >= b' so they are translated to 'b < a' and 'b <= a' respectively
            var invert = op == ExprType.GreaterThan || op == ExprType.GreaterThanOrEqual;

            var metamethod = GetRelationalMetamethod(context, op, left, right);

            if (metamethod != null)
            {
                if (invert)
                {
                    Context.DynamicCache.GetDynamicCall2()(metamethod, right, left);
                }
                else
                {
                    Context.DynamicCache.GetDynamicCall2()(metamethod, left, right);
                }
            }

            // In the absence of a '<=' metamethod, try '<', 'a <= b' is translated to 'not (b < a)'
            if (op != ExprType.LessThanOrEqual && op != ExprType.GreaterThanOrEqual)
            {
                return(false);
            }

            metamethod = GetRelationalMetamethod(context, ExprType.LessThan, left, right);
            if (metamethod != null)
            {
                if (invert)
                {
                    Not(Context.DynamicCache.GetDynamicCall2()(metamethod, right, left));
                }
                else
                {
                    Not(Context.DynamicCache.GetDynamicCall2()(metamethod, left, right));
                }
            }

            var leftTypeName  = BaseLibrary.Type(left);
            var rightTypeName = BaseLibrary.Type(right);

            if (leftTypeName == rightTypeName)
            {
                throw new LuaRuntimeException(ExceptionMessage.OP_TYPE_TWO_ERROR, "compare", leftTypeName);
            }
            throw new LuaRuntimeException(ExceptionMessage.OP_TYPE_WITH_ERROR, "compare", leftTypeName, rightTypeName);
        }
示例#7
0
        public static object ConcatMetamethod(Context context, object left, object right)
        {
            var metamethod = GetMetamethod(context, left, Constant.CONCAT_METAMETHOD) ??
                             GetMetamethod(context, right, Constant.CONCAT_METAMETHOD);

            if (metamethod != null)
            {
                return(Context.DynamicCache.GetDynamicCall2()(metamethod, left, right));
            }

            var typeName = left is string?BaseLibrary.Type(left) : BaseLibrary.Type(right);

            throw new LuaRuntimeException(ExceptionMessage.OP_TYPE_ERROR, "concatenate", typeName);
        }
示例#8
0
        public static object CallMetamethod(Context context, object obj, object[] args)
        {
            var metamethod = GetMetamethod(context, obj, Constant.CALL_METAMETHOD);

            if (metamethod != null)
            {
                var array = new object[args.Length + 1];
                array[0] = obj;
                Array.Copy(args, 0, array, 1, args.Length);
                return(Context.DynamicCache.GetDynamicCall1()(metamethod, new Varargs(array)));
            }

            throw new LuaRuntimeException(ExceptionMessage.OP_TYPE_ERROR, "call", BaseLibrary.Type(obj));
        }
        public AuthenticationContextService(BaseLibrary.Web.IWebContext webContext,
			IAuthenticationContextInitializer[] authenticationContextInitializers,
			AdminSection adminConfig)
        {
            _webContext = webContext;
            _adminConfig = adminConfig;

            AuthenticationSection authSection = WebConfigurationManager.GetSection("zeus/authentication") as AuthenticationSection;
            if (authSection == null)
                authSection = new AuthenticationSection(_adminConfig);
            _rootLocation = authSection.ToAuthenticationLocation();

            foreach (IAuthenticationContextInitializer initializer in authenticationContextInitializers)
                initializer.Initialize(this);
        }
示例#10
0
 public override int CompareTo(BaseLibrary library)
 {
     if (this.GetBooksCount() > library.GetBooksCount())
     {
         return(1);
     }
     else if (this.GetBooksCount() < library.GetBooksCount())
     {
         return(-1);
     }
     else
     {
         return(0);
     }
 }
示例#11
0
        public static object NumericMetamethod(Context context, ExprType op, object left, object right)
        {
            var methodName = GetMethodName(op);

            var metamethod = GetMetamethod(context, left, methodName) ?? GetMetamethod(context, right, methodName);

            if (metamethod != null)
            {
                return(Context.DynamicCache.GetDynamicCall2()(metamethod, left, right));
            }

            var typeName = BaseLibrary.Type(BaseLibrary.ToNumber(left) == null ? left : right);

            throw new LuaRuntimeException(ExceptionMessage.OP_TYPE_ERROR, "perform arithmetic on", typeName);
        }
示例#12
0
        public static object NewIndexMetamethod(Context context, object obj, object key, object value)
        {
            var metamethod = GetMetamethod(context, obj, Constant.NEWINDEX_METAMETHOD);

            if (metamethod != null)
            {
                if (metamethod is Delegate)
                {
                    return(Context.DynamicCache.GetDynamicCall3()(metamethod, obj, key, value));
                }
                if (metamethod is LuaTable)
                {
                    return(Context.DynamicCache.GetDynamicNewIndex()(obj, key, value));
                }
            }

            if (obj is LuaTable)
            {
                return(null);
            }
            throw new LuaRuntimeException(ExceptionMessage.OP_TYPE_ERROR, "index", BaseLibrary.Type(obj));
        }
示例#13
0
        public static object UnaryMinusMetamethod(Context context, object obj)
        {
            var metamethod = GetMetamethod(context, obj, Constant.UNARYMINUS_METAMETHOD);

            if (metamethod != null)
            {
                return(Context.DynamicCache.GetDynamicCall1()(metamethod, obj));
            }

            throw new LuaRuntimeException(ExceptionMessage.OP_TYPE_ERROR, "perform arithmetic on", BaseLibrary.Type(obj));
        }
示例#14
0
        public static object LengthMetamethod(Context context, object obj)
        {
            var metamethod = GetMetamethod(context, obj, Constant.LENGTH_METAMETHOD);

            if (metamethod != null)
            {
                return(Context.DynamicCache.GetDynamicCall1()(metamethod, obj));
            }

            throw new LuaRuntimeException(ExceptionMessage.OP_TYPE_ERROR, "get length of", BaseLibrary.Type(obj));
        }
示例#15
0
 public AuthenticationService(BaseLibrary.Web.IWebContext webContext, AuthenticationLocation config, string loginUrl)
 {
     _webContext = webContext;
     _config = config;
     _loginUrl = loginUrl;
 }