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)));
        }
예제 #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)));
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
     }
 }
예제 #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);
        }
예제 #10
0
        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));
        }
예제 #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));
        }
예제 #12
0
        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);
        }
예제 #13
0
        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);
        }
예제 #14
0
        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));
        }
예제 #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);
        }
예제 #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);
        }
예제 #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));
        }
예제 #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);
        }
예제 #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]);
        }
예제 #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]);
        }
예제 #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()));
        }
예제 #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));
        }
예제 #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));
        }
예제 #24
0
        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));
        }
예제 #25
0
        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.");
                }
            }
        }
예제 #26
0
        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.");
                }
            }
        }
예제 #27
0
 public Variable(string name, SkryptObject value, LexicalEnvironment lexicalEnvironment) : this(name, value)
 {
     LexicalEnvironment = lexicalEnvironment;
 }
예제 #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;