Пример #1
0
        public JSListInstance FindAll(object a)
        {
            if (!(a is UserDefinedFunction))
            {
                throw new JavaScriptException(this.Engine, ErrorType.Error, "expecting comparison function");
            }

            UserDefinedFunction f    = (UserDefinedFunction)a;
            List <object>       list = new List <object>();

            foreach (object obj in this.array)
            {
                if (TypeConverter.ToBoolean(f.Call(this.Engine.Global, obj)))
                {
                    list.Add(obj);
                }
            }

            JSListInstance result = new JSListInstance(this.Engine.Object.InstancePrototype);

            foreach (object obj in list)
            {
                result.Add(obj);
            }

            return(result);
        }
Пример #2
0
        public static void Records(ScriptEngine eng, object f)
        {
            if (f is UserDefinedFunction)
            {
                UserDefinedFunction function = (UserDefinedFunction)f;

                try
                {
                    Server.Users.Records(x => function.Call(eng.Global,
                                                            new Objects.JSRecord(eng.Object.InstancePrototype, x, eng.UserData as string)));
                }
                catch { }
            }
        }
        public static void Banned(ScriptEngine eng, object f)
        {
            if (f is UserDefinedFunction)
            {
                UserDefinedFunction function = (UserDefinedFunction)f;

                try
                {
                    Server.Users.Banned(x => function.Call(eng.Global,
                                                           new Objects.JSBannedUser(eng.Object.InstancePrototype, x, eng.ScriptName)));
                }
                catch { }
            }
        }
Пример #4
0
        public void R_Users(object a)
        {
            if (a is UserDefinedFunction)
            {
                UserDefinedFunction f = (UserDefinedFunction)a;

                this.UserList.ForEach(x =>
                {
                    try { f.Call(this.Engine.Global, x); }
                    catch (Jurassic.JavaScriptException je)
                    {
                        ScriptManager.ErrorHandler(f.Engine.ScriptName, je.LineNumber, je.Message);
                    }
                    catch { }
                });
            }
        }
Пример #5
0
        public void Users(object a)
        {
            if (a is UserDefinedFunction)
            {
                JSScript script = ScriptManager.Scripts.Find(x => x.ScriptName == this.ScriptName);

                if (script != null)
                {
                    UserDefinedFunction x = (UserDefinedFunction)a;

                    try
                    {
                        this.users.ForEach(z => x.Call(script.JS.Global, z));
                    }
                    catch { }
                }
            }
        }
Пример #6
0
        public static void DoRoomsTask(ScriptEngine eng, object a)
        {
            if (a is UserDefinedFunction)
            {
                UserDefinedFunction f      = (UserDefinedFunction)a;
                JSScript            script = ScriptManager.Scripts.Find(x => x.ScriptName == eng.ScriptName);

                if (script != null)
                {
                    foreach (Objects.JSRoom r in script.Rooms)
                    {
                        try { f.Call(script.JS.Global, r); }
                        catch (Jurassic.JavaScriptException je)
                        {
                            ScriptManager.ErrorHandler(f.Engine.ScriptName, je.LineNumber, je.Message);
                        }
                    }
                }
Пример #7
0
        public static void Local(ScriptEngine eng, object f)
        {
            if (f is UserDefinedFunction)
            {
                JSScript script = ScriptManager.Scripts.Find(x => x.ScriptName == eng.UserData as string);

                if (script != null)
                {
                    UserDefinedFunction function = (UserDefinedFunction)f;

                    try
                    {
                        script.local_users.ForEach(u => function.Call(eng.Global, u));
                    }
                    catch { }
                }
            }
        }
Пример #8
0
        public int FindLastIndex(object a)
        {
            if (!(a is UserDefinedFunction))
            {
                throw new JavaScriptException(this.Engine, ErrorType.Error, "expecting comparison function");
            }

            UserDefinedFunction f = (UserDefinedFunction)a;

            for (int i = (this.array.Length - 1); i > -1; i--)
            {
                if (TypeConverter.ToBoolean(f.Call(this.Engine.Global, this.array[i])))
                {
                    return(i);
                }
            }

            return(-1);
        }
Пример #9
0
        public object Find(object a)
        {
            if (!(a is UserDefinedFunction))
            {
                throw new JavaScriptException(this.Engine, ErrorType.Error, "expecting comparison function");
            }

            UserDefinedFunction f = (UserDefinedFunction)a;

            foreach (object obj in this.array)
            {
                if (TypeConverter.ToBoolean(f.Call(this.Engine.Global, obj)))
                {
                    return(obj);
                }
            }

            return(null);
        }
        public int FindIndex(object a)
        {
            if (!(a is UserDefinedFunction))
            {
                throw new JavaScriptException(this.Engine, "invalid casting", "expecting comparison function");
            }

            UserDefinedFunction f = (UserDefinedFunction)a;

            for (int i = 0; i < this.array.Length; i++)
            {
                if (TypeConverter.ToBoolean(f.Call(this.Engine.Global, this.array[i])))
                {
                    return(i);
                }
            }

            return(-1);
        }
Пример #11
0
        public bool Sort(object a)
        {
            if (this.array.Length < 2)
            {
                return(false);
            }

            if (a is Undefined)
            {
                List <object> nocomp = this.array.ToList();
                nocomp.Sort();

                this.array = nocomp.ToArray();

                for (uint i = 0; i < this.array.Length; i++)
                {
                    this.SetPropertyValue(i, this.array[i], true);
                }

                return(true);
            }

            if (!(a is UserDefinedFunction))
            {
                throw new JavaScriptException(this.Engine, ErrorType.Error, "expecting comparison function");
            }

            UserDefinedFunction f    = (UserDefinedFunction)a;
            List <object>       list = this.array.ToList();

            list.Sort((x, y) => TypeConverter.ToInt32(f.Call(this.Engine, x, y)));

            this.array = list.ToArray();

            for (uint i = 0; i < this.array.Length; i++)
            {
                this.SetPropertyValue(i, this.array[i], true);
            }

            return(true);
        }
        public static void Leaves(ScriptEngine eng, object f)
        {
            if (Server.Link.IsLinked)
            {
                if (f is UserDefinedFunction)
                {
                    JSScript script = ScriptManager.Scripts.Find(x => x.ScriptName == eng.ScriptName);

                    if (script != null)
                    {
                        UserDefinedFunction function = (UserDefinedFunction)f;

                        try
                        {
                            script.leaves.ForEach(l => function.Call(eng.Global, l));
                        }
                        catch { }
                    }
                }
            }
        }
Пример #13
0
        public int RemoveAll(object a)
        {
            if (!(a is UserDefinedFunction))
            {
                throw new JavaScriptException(this.Engine, ErrorType.Error, "expecting comparison function");
            }

            UserDefinedFunction f    = (UserDefinedFunction)a;
            List <object>       list = new List <object>();

            foreach (object obj in this.array)
            {
                if (!TypeConverter.ToBoolean(f.Call(this.Engine.Global, obj)))
                {
                    list.Add(obj);
                }
            }

            int current = this.array.Length;

            this.array = new object[list.Count];

            for (uint i = 0; i < current; i++)
            {
                if (i < this.array.Length)
                {
                    this.array[i] = list[(int)i];
                    this.SetPropertyValue(i, this.array[i], true);
                }
                else
                {
                    this.Delete(i, true);
                }
            }

            return(current - this.array.Length);
        }