示例#1
0
        /// <summary>Executes the command.</summary>
        /// <param name="queue">The command queue involved.</param>
        /// <param name="entry">Entry to be executed.</param>
        public static void Execute(CommandQueue queue, CommandEntry entry)
        {
            TemplateObject obj      = entry.GetArgumentObject(queue, 0);
            FunctionTag    function = FunctionTag.CreateFor(obj, queue.GetTagData());

            if (function == null)
            {
                queue.HandleError(entry, "Cannot call function '" + TextStyle.Separate + obj.ToString() + TextStyle.Base + "': it does not exist!");
                return;
            }
            CommandScript script = function.Internal;

            if (entry.ShouldShowGood(queue))
            {
                entry.GoodOutput(queue, "Calling '" + function.GetDebugString() + TextStyle.Base + "'...");
            }
            CompiledCommandRunnable runnable = script.Compiled.ReferenceCompiledRunnable.Duplicate();

            if (runnable.Entry.Entries.Length > 0)
            {
                Dictionary <string, SingleCILVariable> varlookup = runnable.Entry.Entries[0].VarLookup;
                foreach (string var in entry.NamedArguments.Keys)
                {
                    if (!var.StartsWithNull())
                    {
                        if (varlookup.TryGetValue(var, out SingleCILVariable varx))
                        {
                            // TODO: Type verification!
                            runnable.Entry.GetSetter(varx.Index).Invoke(runnable, entry.GetNamedArgumentObject(queue, var));
                        }
                    }
                }
            }
            if (entry.NamedArguments.ContainsKey(CommandEntry.SAVE_NAME_ARG_ID))
            {
                bool   sgood = entry.ShouldShowGood(queue);
                string vname = entry.NamedArguments[CommandEntry.SAVE_NAME_ARG_ID].ToString();
                if (sgood)
                {
                    entry.GoodOutput(queue, "Noticing variable track for " + vname + ".");
                }
                CompiledCommandRunnable curRunnable = queue.CurrentRunnable;
                if (!entry.VarLookup.TryGetValue(vname, out SingleCILVariable locVar))
                {
                    queue.HandleError(entry, "Invalid save-to variable: " + vname + "!");
                    return;
                }
                runnable.Callback = () =>
                {
                    // TODO: Fix!

                    /*if (runnable.Entry.Entries.Length > 0)
                     * {
                     *  MapTag mt = new MapTag();
                     *  Dictionary<string, SingleCILVariable> varlookup = runnable.Entry.Entries[0].VarLookup;
                     *  foreach (SingleCILVariable vara in varlookup.Values)
                     *  {
                     *      if (runnable.LocalVariables[vara.Index].Internal != null)
                     *      {
                     *          mt.Internal.Add(vara.Name, runnable.LocalVariables[vara.Index].Internal);
                     *      }
                     *  }
                     *  curRunnable.LocalVariables[locVar.Index].Internal = mt;
                     * }*/
                    if (sgood)
                    {
                        entry.GoodOutput(queue, "Call complete.");
                    }
                };
            }
            queue.RunningStack.Push(runnable);
        }
示例#2
0
 /// <summary>Handles the base input for a tag.</summary>
 /// <param name="data">The tag data.</param>
 /// <returns>The correct object.</returns>
 public static FunctionTag HandleOne(TagData data)
 {
     return(FunctionTag.CreateFor(data.GetModifierObjectCurrent(), data));
 }