Exemple #1
0
        /* function foo(a) [share c]
         * {
         *    var b;
         *    var d;
         *    return ->d;
         * }
        */

        public static void Test1(StackContext sctx, PValue[] args, PVariable[] sharedVariables,
            out PValue result)
        {
            var a = args[0];
            var b = PType.Null.CreatePValue();
            var c = sharedVariables[0];
            var d = new PVariable();
            d.Value = PType.Null;

            var argv = new[] {a, b};

            a = new PValue(true, PType.Bool);
            b = sctx.CreateNativePValue(sctx.ParentApplication.Functions["funcid"]);

            a.DynamicCall(sctx, null, PCall.Get, "memid");

            result = sctx.CreateNativePValue(d);
        }
Exemple #2
0
 private static IEnumerable<PValue> _wrapDynamicIEnumerable(StackContext sctx, PValue psource)
 {
     var pvEnumerator =
         psource.DynamicCall(sctx, Runtime.EmptyPValueArray, PCall.Get, "GetEnumerator").
             ConvertTo(sctx, typeof (IEnumerator));
     var enumerator = (IEnumerator) pvEnumerator.Value;
     PValueEnumerator pvEnum;
     try
     {
         if ((pvEnum = enumerator as PValueEnumerator) != null)
         {
             while (pvEnum.MoveNext())
                 yield return pvEnum.Current;
         }
         else
         {
             while (enumerator.MoveNext())
                 yield return sctx.CreateNativePValue(enumerator.Current);
         }
     }
     finally
     {
         var disposable = enumerator as IDisposable;
         if (disposable != null)
             disposable.Dispose();
     }
 }
Exemple #3
0
        /// <summary>
        ///     Implementation of (obj, id, arg1, arg2, arg3, ..., argn) => obj.id(arg1, arg2, arg3, ..., argn);
        /// </summary>
        /// <param name = "sctx">The stack context in which to call the member of <paramref name = "obj" />.</param>
        /// <param name = "obj">The obj to call.</param>
        /// <param name = "isSet">Indicates whether to perform a Set-call.</param>
        /// <param name = "id">The id of the member to call.</param>
        /// <param name = "args">The array of arguments to pass to the member call.<br />
        ///     Lists and coroutines are expanded.</param>
        /// <returns>The result returned by the member call.</returns>
        /// <exception cref = "ArgumentNullException"><paramref name = "sctx" /> is null.</exception>
        public PValue Run(StackContext sctx, PValue obj, bool isSet, string id, params PValue[] args)
        {
            if (obj == null)
                return PType.Null.CreatePValue();
            if (sctx == null)
                throw new ArgumentNullException("sctx");
            if (args == null)
                args = new PValue[] {};

            var iargs = new List<PValue>();
            for (var i = 0; i < args.Length; i++)
            {
                var arg = args[i];
                var folded = Map._ToEnumerable(sctx, arg);
                if (folded == null)
                    iargs.Add(arg);
                else
                    iargs.AddRange(folded);
            }

            return obj.DynamicCall(sctx, iargs.ToArray(), isSet ? PCall.Set : PCall.Get, id);
        }