/// <summary> /// Execute a line of code. /// </summary> /// <param name="sender"></param> /// <param name="line"></param> /// <param name="output"></param> internal void ExecLine(Context sender, string line, StringBuilder output) { var log = sender.Root.Log; string key; Variable[] args; int i = 0; char c; while (i < line.Length && !sender.ExitLine) { c = line[i]; ++i; switch (c) { case '#': case '@': execSplitCommand(sender, line, ref i, out key, out args); if (key != null) { Variable variable = sender.Get(new Key(key, sender), log); if (variable == null || variable.IsSet == false) continue; var func = variable.Value as Function; if (func != null) variable = func(sender, args); // ToDo : Do we need to do anything to other value types? // output if @ if (c == '@' && variable != null) variable.WriteValueUser(sender, output); } else { if (c == '@' && args != null && args.Length > 0 && args[0] != null) args[0].WriteValueUser(sender, output); } break; //case '\\': // ToDo : escape character. //break; default: output.Append(c); break; } } }
/// <summary> /// Check whats in sb, then add it to the list. /// [float, bool, and, or, variable] /// </summary> /// <returns>false if nothing was added.</returns> private void execParenthCheckAdd(Context sender, List<execParenthItem> items, StringBuilder sb) { if (sb.Length == 0) return; bool isFloat; bool isPercent; string str = KeyClean(sb.ToString(), out isFloat, out isPercent, sender.Root.Log); sb.Clear(); if (str == null) return; // is str float? if (isFloat) items.Add(new Variable(float.Parse(str))); // percent to float? else if (isPercent) items.Add(new Variable(float.Parse(str) * 0.01f)); // bool else if (str == "true") items.Add(new Variable(true)); else if (str == "false") items.Add(new Variable(false)); // logic operators else if (str == "not") items.Add(Operators.Not); else if (str == "and") items.Add(Operators.And); else if (str == "or") items.Add(Operators.Or); else // variable items.Add(sender.Get(new Key(str, sender))); return; }