public static SkryptObject Contains(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var str   = self as StringInstance;
            var input = arguments.GetAs <StringInstance>(0);

            return(engine.CreateBoolean(str.Value.Contains(input.Value)));
        }
        public static SkryptObject Replace(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var str         = self as StringInstance;
            var input       = arguments.GetAs <StringInstance>(0);
            var replacement = arguments.GetAs <StringInstance>(1);

            return(engine.CreateString(str.Value.Replace(input.Value, replacement.Value)));
        }
Esempio n. 3
0
        public static SkryptObject Read(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var destination = arguments.GetAs <StringInstance>(0);

            var str = engine.CreateString(engine.FileHandler.Read(destination));

            return(str);
        }
        public SkryptObject Get(SkryptObject index)
        {
            if (index is NumberInstance number && number >= 0 && number % 1 == 0)
            {
                return(Get((int)number));
            }

            return(Engine.CreateString(string.Empty));
        }
        public static SkryptObject Reverse(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var str = self as StringInstance;

            char[] charArray = str.Value.ToCharArray();
            Array.Reverse(charArray);

            return(engine.CreateString(new string(charArray)));
        }
Esempio n. 6
0
        public static SkryptObject ReadAsync(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var destination = arguments.GetAs <StringInstance>(0);
            var function    = arguments.GetAs <FunctionInstance>(1);

            engine.FileHandler.ReadAsync(destination, function);

            return(null);
        }
Esempio n. 7
0
        public static SkryptObject Write(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var destination = arguments.GetAs <StringInstance>(0);
            var content     = arguments.GetAs <SkryptObject>(1).ToString();

            engine.FileHandler.Write(destination, content);

            return(null);
        }
Esempio n. 8
0
 internal void SetGlobal(string name, SkryptObject value)
 {
     if (GlobalEnvironment.Variables.ContainsKey(name))
     {
         GlobalEnvironment.Variables[name].Value = value;
     }
     else
     {
         GlobalEnvironment.Variables[name] = new Variable(name, value);
     }
 }
Esempio n. 9
0
        public bool TryGetValue(string name, out SkryptObject value)
        {
            if (GlobalEnvironment.Variables.ContainsKey(name))
            {
                value = GlobalEnvironment.Variables[name].Value;

                return(true);
            }

            value = null;
            return(false);
        }
        public static SkryptObject Length2(SkryptEngine engine, SkryptObject self)
        {
            double val    = 0;
            var    vector = self as VectorInstance;

            for (var i = 0; i < vector.Components.Length; i++)
            {
                val += Math.Pow(vector.Components[i], 2);
            }

            return(engine.CreateNumber(val));
        }
Esempio n. 11
0
        public static SkryptObject GetSizeOfAction(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var target = arguments.GetAs <FunctionInstance>(0);

            var before = SkryptEngine.GetAllocatedBytesForCurrentThread();

            target.Run();

            var after = SkryptEngine.GetAllocatedBytesForCurrentThread();

            return(engine.CreateNumber(after - before));
        }
        public static SkryptObject ToArray(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var str = self as StringInstance;

            var charArray = str.Value.ToCharArray();
            var array     = engine.CreateArray(new SkryptObject[0]);

            for (var i = 0; i < charArray.Length; i++)
            {
                ArrayInstance.Push(engine, array, new Arguments(engine.CreateString("" + charArray[i])));
            }

            return(array);
        }
        public static SkryptObject ToByteArray(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var str = self as StringInstance;

            var bytes = Encoding.ASCII.GetBytes(str.Value);
            var array = engine.CreateArray(new SkryptObject[0]);

            for (var i = 0; i < bytes.Length; i++)
            {
                ArrayInstance.Push(engine, array, new Arguments(engine.CreateNumber(bytes[i])));
            }

            return(array);
        }
        public static SkryptObject PadRight(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var str        = (self as StringInstance).Value;
            var totalWidth = arguments.GetAs <NumberInstance>(0);
            var input      = arguments.GetAs <StringInstance>(1);
            var newStr     = "";

            while (newStr.Length < totalWidth)
            {
                newStr = newStr + input;
            }

            return(engine.CreateString(str + newStr));
        }
Esempio n. 15
0
        public static SkryptObject Constructor(SkryptEngine engine, SkryptObject self, SkryptObject[] input)
        {
            var x = TypeConverter.ToNumeric(input, 0);
            var y = TypeConverter.ToNumeric(input, 1);
            var z = TypeConverter.ToNumeric(input, 2);

            var vec = (Vector)self;

            vec.X = x;
            vec.Y = y;
            vec.Z = z;

            return(vec);
        }
Esempio n. 16
0
        public static SkryptObject Assert(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var condition = arguments.GetAs <BooleanInstance>(0);

            var message = arguments.Length > 1 ? arguments.GetAs <StringInstance>(1) : "Assertion failed!";

            if (!condition)
            {
                Console.WriteLine(message);

                Console.WriteLine(CallStack(engine, self, arguments));
            }

            return(condition);
        }
Esempio n. 17
0
        public static SkryptObject GetSizeOfObject(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var target = arguments.GetAs <SkryptObject>(0);
            var clone  = default(SkryptObject);

            var before = SkryptEngine.GetAllocatedBytesForCurrentThread();

            clone = target != null?target.Clone() : null;

            var after = SkryptEngine.GetAllocatedBytesForCurrentThread();

            clone = null;

            return(engine.CreateNumber(after - before));
        }
Esempio n. 18
0
        public static SkryptObject Min(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var minValue = default(NumberInstance);

            for (int i = 0; i < arguments.Values.Length; i++)
            {
                var num = arguments.GetAs <NumberInstance>(i);

                if (num.Value < minValue.Value)
                {
                    minValue = num;
                }
            }

            return(minValue);
        }
Esempio n. 19
0
        public Member SetProperty(string name, SkryptObject value)
        {
            if (!Members.ContainsKey(name))
            {
                throw new NonExistingMemberException($"Value does not contain a member with the name '{name}'.");
            }

            if (value is FunctionInstance function)
            {
                function.Self = this;
            }

            Members[name].value = value;

            return(Members[name]);
        }
Esempio n. 20
0
        public Member CreateProperty(string name, SkryptObject value, bool isPrivate = false, bool isConstant = false)
        {
            Members[name] = new Member()
            {
                value      = value,
                isConstant = isConstant,
                isPrivate  = isPrivate
            };

            if (value is FunctionInstance function)
            {
                function.Self = this;
            }

            return(Members[name]);
        }
Esempio n. 21
0
        public static SkryptObject RandomInt(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            if (arguments.Values.Length == 1)
            {
                return(engine.CreateNumber((int)(_random.NextDouble() * arguments.GetAs <NumberInstance>(0).Value)));
            }
            else if (arguments.Values.Length == 2)
            {
                var val = _random.NextDouble();
                var min = arguments.GetAs <NumberInstance>(0).Value;
                var max = arguments.GetAs <NumberInstance>(1).Value;

                return(engine.CreateNumber((int)(max * val + min * (1 - val))));
            }

            return(engine.CreateNumber((int)_random.NextDouble()));
        }
Esempio n. 22
0
        public static SkryptObject CallStack(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            int    i     = 0;
            int    count = engine.CallStack.Count();
            string str   = "";

            foreach (Call c in engine.CallStack)
            {
                var file = i == count - 1 ? c.callFile : c.file;
                file = file ?? c.callFile;

                str += $"\tat {c.name}() in {file} ({c.line},{c.column})\n";

                i++;
            }

            return(engine.CreateString(str));
        }
Esempio n. 23
0
        public static SkryptObject FromByteArray(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var array     = arguments.GetAs <ArrayInstance>(0);
            var rawString = "";

            for (var i = 0; i < array.SequenceValues.Count; i++)
            {
                var rawValue = array.SequenceValues[i];

                if (rawValue is NumberInstance num)
                {
                    rawString += (char)num.Value;
                }
                else
                {
                    throw new FatalErrorException("Number expected.");
                }
            }

            return(engine.CreateString(rawString));
        }
        public static SkryptObject Split(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var str   = self as StringInstance;
            var input = new List <string>();

            for (int i = 0; i < arguments.Values.Length; i++)
            {
                var s = arguments.GetAs <StringInstance>(i);

                input.Add(s.Value);
            }

            var split = str.Value.Split(input.ToArray(), StringSplitOptions.None);

            var stringArray = new StringInstance[split.Length];

            for (int i = 0; i < split.Length; i++)
            {
                stringArray[i] = engine.CreateString(split[i]);
            }

            return(engine.CreateArray(stringArray));
        }
        public static SkryptObject Substring(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var str   = self as StringInstance;
            var start = arguments.GetAs <NumberInstance>(0);
            var end   = arguments[1];

            if (end == null)
            {
                return(engine.CreateString(str.Value.Substring((int)start)));
            }
            else
            {
                if (end is NumberInstance)
                {
                    var length = Math.Max(Math.Min((int)(NumberInstance)end, str.Value.Length - 1) - (int)start, 0);

                    return(engine.CreateString(str.Value.Substring((int)start, length)));
                }
                else
                {
                    throw new InvalidArgumentTypeException($"Expected argument of type Number.");
                }
            }
        }
        public static SkryptObject IndexOf(SkryptEngine engine, SkryptObject self, Arguments arguments)
        {
            var str    = self as StringInstance;
            var search = arguments.GetAs <StringInstance>(0);
            var start  = arguments[1];

            if (start == null)
            {
                return(engine.CreateNumber(str.Value.IndexOf(search)));
            }
            else
            {
                if (start is NumberInstance num)
                {
                    var startIndex = Math.Max(Math.Min((int)num, str.Value.Length - 1), 0);

                    return(engine.CreateNumber(str.Value.IndexOf(search, startIndex)));
                }
                else
                {
                    throw new InvalidArgumentTypeException($"Expected argument of type Number.");
                }
            }
        }
Esempio n. 27
0
 public Variable(string name, SkryptObject value, LexicalEnvironment lexicalEnvironment) : this(name, value)
 {
     LexicalEnvironment = lexicalEnvironment;
 }
Esempio n. 28
0
 public Variable(string name, SkryptObject value) : this(name) {
     Value = value;
 }
 public static SkryptObject IsInRange(SkryptEngine engine, SkryptObject self, Arguments arguments) => null;
 public static SkryptObject Get(SkryptEngine engine, SkryptObject self, Arguments arguments) => null;