Пример #1
0
 /// <summary>
 /// Gets the value of a global variable.
 /// </summary>
 /// <param name="name">The name of the gloable variable</param>
 /// <returns></returns>
 public static TsObject VariableGlobalGet(string name)
 {
     if (TsInstance.Global._members.TryGetValue(name, out var result))
     {
         return(result);
     }
     return(TsObject.Empty());
 }
Пример #2
0
        /// <summary>
        /// Copies one TS array into another, resizing the destination if needed.
        /// </summary>
        /// <param name="dest"></param>
        /// <param name="destIndex"></param>
        /// <param name="src"></param>
        /// <param name="srcIndex"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static TsObject ArrayCopy(TsObject src, int srcIndex, TsObject dest, int destIndex, int length)
        {
            //We need to get the value wrapper in case we need to resize the internal array.
            var destWrapper = dest.Value as TsMutableValue <TsObject[]> ?? throw new ArgumentException("Can only copy 1D arrays", "dest");
            var srcWrapper  = src.Value as TsMutableValue <TsObject[]> ?? throw new ArgumentException("Can only copy 1D arrays", "src");
            var destValue   = destWrapper.StrongValue;
            var srcValue    = srcWrapper.StrongValue;

            if (destIndex + length >= destValue.Length)
            {
                var temp = new TsObject[destIndex + length + 1];
                Array.Copy(destValue, 0, temp, 0, destValue.Length);
                destValue = temp;
                destWrapper.StrongValue = destValue;
            }
            Array.Copy(srcValue, srcIndex, destValue, destIndex, length);
            return(TsObject.Empty());
        }
Пример #3
0
        public static TsObject ArrayCreate(ITsInstance target, TsObject[] args)
        {
            var size  = args[0].GetInt();
            var value = TsObject.Empty();

            if (args.Length > 1)
            {
                value = args[1];
            }
            var result = new TsObject[size];

            for (var i = 0; i < size; ++i)
            {
                result[i] = value;
            }

            return(new TsObject(result));
        }
Пример #4
0
        public static TsObject EventPerform(ITsInstance inst, TsObject[] args)
        {
            if (inst.TryGetDelegate((string)args[1], out var ev))
            {
                TsObject[] copy;
                if (args.Length > 2)
                {
                    copy = new TsObject[args.Length - 2];
                    Array.Copy(args, 2, copy, 0, copy.Length);
                }
                else
                {
                    copy = null;
                }

                return(ev.Invoke(args[0].GetInstance(), copy));
            }
            return(TsObject.Empty());
        }
Пример #5
0
        public static TsObject CallInstanceScript(ITsInstance inst, TsObject[] args)
        {
            if (TsReflection.TryGetScript((string)args[1], (string)args[2], out var ev))
            {
                TsObject[] copy;
                if (args.Length > 3)
                {
                    copy = new TsObject[args.Length - 3];
                    Array.Copy(args, 3, copy, 0, copy.Length);
                }
                else
                {
                    copy = null;
                }

                return(ev.Invoke(args[0].GetInstance(), copy));
            }
            return(TsObject.Empty());
        }