Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Executes the unbind command on a <see cref = "PValue" /> argument.
        ///     The argument must either be the variable's name as a string or a 
        ///     reference to the <see cref = "PVariable" /> object.
        /// </summary>
        /// <param name = "sctx">The <see cref = "FunctionContext" /> to modify.</param>
        /// <param name = "arg">A variable reference or name.</param>
        /// <returns>Always {~Null}</returns>
        /// <exception cref = "ArgumentNullException"><paramref name = "sctx" /> is null</exception>
        /// <exception cref = "ArgumentNullException"><paramref name = "arg" /> is null</exception>
        /// <exception cref = "PrexoniteException"><paramref name = "arg" /> contains null</exception>
        /// <exception cref = "PrexoniteException"><paramref name = "sctx" /> is not a <see cref = "FunctionContext" /></exception>
        public static PValue Run(StackContext sctx, PValue arg)
        {
            if (sctx == null)
                throw new ArgumentNullException("sctx");

            if (arg == null)
                throw new ArgumentNullException("arg");

            if (arg.IsNull)
                throw new PrexoniteException("The unbind command cannot process Null.");

            var fctx = sctx as FunctionContext;
            if (fctx == null)
                throw new PrexoniteException(
                    "The unbind command can only work on function contexts.");

            string id;

            if (arg.Type is ObjectPType && arg.Value is PVariable)
            {
                //Variable reference
                id = (from pair in fctx.LocalVariables
                      where ReferenceEquals(pair.Value, arg.Value)
                      select pair.Key
                    ).FirstOrDefault();
            }
            else
            {
                throw new PrexoniteException("Unbind requires variable references as arguments.");
            }

            PVariable existing;
            if (id != null && fctx.LocalVariables.TryGetValue(id, out existing))
            {
                var unbound = new PVariable {Value = existing.Value};
                fctx.ReplaceLocalVariable(id, unbound);
            }

            return PType.Null.CreatePValue();
        }