コード例 #1
0
    int ExecuteLine(string LineToExecute, int Value)
    {
        string FindVariable = LineToExecute;

        //MAY CAUSE FATAL ERROR v (but also, it can break game if remove)
        bool quit    = false;
        int  blocker = 0;

        while (FindVariable.Contains("Input."))
        {
            int ind = FindVariable.IndexOf("Input.") + 6;
            //Debug.Log("ind: " + ind);
            int    e     = 0;
            string comp  = "Input.";
            string value = "error";
            for (int d = 0; d < 256; d++)
            {
                //Debug.Log(FindVariable[ind+d]);
                if (char.IsLetterOrDigit(FindVariable[ind + d]))
                {
                    comp += FindVariable[ind + d].ToString();
                }
                else
                {
                    break;
                }
            }
            e = ind - 6 + comp.Length;
            //Debug.Log("comp: " + comp);
            //Debug.Log("e: " + e);
            for (int inp = 0; inp < InputI.DataId.Length; inp++)
            {
                if (comp == InputI.DataId[inp])
                {
                    value = InputI.Data[inp];
                }
            }
            if (value == "error")
            {
                quit = true;
            }
            FindVariable = FindVariable.Remove(ind - 6, e - ind + 6);
            FindVariable = FindVariable.Insert(ind - 6, value);
            //Debug.Log(FindVariable.Substring(ind-6, e-ind+6));
            //Debug.Log("FindVariable: " + FindVariable);
            if (quit || blocker >= 64)
            {
                break;
            }
            blocker++;
        }

        foreach (string FunctionRead in FunctionNames)
        {
            if (LineToExecute.Replace("\t", string.Empty).StartsWith(FunctionRead) || LineToExecute.Replace("\t", string.Empty).StartsWith(FunctionRead.Replace(" ", string.Empty)))
            {
                ReadFunction(FunctionRead.Replace("()", string.Empty).Replace(" ", string.Empty));
            }
        }
        if (LineToExecute.Replace("\t", string.Empty).StartsWith("print") || LineToExecute.Replace("\t", string.Empty).StartsWith("Debug.Log") && LineToExecute.EndsWith(";"))
        {
            Debug.Log(SearchInString("(\"", "\")", LineToExecute.Replace("\t", string.Empty)).Replace("\"", string.Empty));
        }
        else if (LineToExecute.Replace("\t", string.Empty).StartsWith("if") && LineToExecute.EndsWith("{"))
        {
            if (CompileClass.ReadBoolean(SearchInString("(", ")", FindVariable)) == "true")
            {
                int TabsCount = 0;
                foreach (char c in LineToExecute)
                {
                    if (c == '\t')
                    {
                        TabsCount++;
                    }
                }
                for (int l = Value + 1; l < Lines.Length; l++)
                {
                    int CLTabsCount = 0;
                    foreach (char c in Lines[l])
                    {
                        if (c == '\t')
                        {
                            CLTabsCount++;
                        }
                    }
                    if (Lines[l].EndsWith("}") && CLTabsCount == TabsCount)
                    {
                        break;
                    }
                    else if (Lines[l].EndsWith("{"))
                    {
                        for (int LineScanner = l; Lines[LineScanner].EndsWith("}"); LineScanner++)
                        {
                            l = LineScanner;
                        }
                        l++;
                    }
                    else
                    {
                        ExecuteLine(Lines[l], l);
                    }
                }
            }
            else
            {
                /*int SCount = 0;
                 * //Else/ElseIf
                 * int TabsCount = 0;
                 * foreach(char c in LineToExecute) {
                 *      if(c == '\t') TabsCount++;
                 * }
                 * for(int l = Value + 1; l < Lines.Length; l++) {
                 *      int CLTabsCount = 0;
                 *      foreach(char c in Lines[l]) {
                 *              if(c == '\t') CLTabsCount++;
                 *      }
                 *      if(Lines[l].EndsWith("}") && CLTabsCount == TabsCount) {
                 *              break;
                 *      } else if(Lines[l].EndsWith("{")) {
                 *              for(int LineScanner = l; Lines[LineScanner].EndsWith("}"); LineScanner++) {
                 *                      l = LineScanner;
                 *              }
                 *              l++;
                 *      } else {
                 *              SCount++;
                 *      }
                 * }*/
            }
        }
        else if (LineToExecute.Replace("\t", string.Empty).StartsWith("Output.Send") && LineToExecute.EndsWith(");"))
        {
            //All Output witch contains var: Var's name will be replace with value

            string IncludeVar = LineToExecute;

            //MAY CAUSE FATAL ERROR v (but also, it can break game if remove)
            bool quit2    = false;
            int  blocker2 = 0;
            while (IncludeVar.Contains("Input."))
            {
                int ind = IncludeVar.IndexOf("Input.") + 6;
                //Debug.Log("ind: " + ind);
                int    e     = 0;
                string comp  = "Input.";
                string value = "error";
                for (int d = 0; d < 256; d++)
                {
                    //Debug.Log(FindVariable[ind+d]);
                    if (char.IsLetterOrDigit(IncludeVar[ind + d]))
                    {
                        comp += IncludeVar[ind + d].ToString();
                    }
                    else
                    {
                        break;
                    }
                }
                e = ind - 6 + comp.Length;
                //Debug.Log("comp: " + comp);
                //Debug.Log("e: " + e);
                for (int inp = 0; inp < InputI.DataId.Length; inp++)
                {
                    if (comp == InputI.DataId[inp])
                    {
                        value = InputI.Data[inp];
                    }
                }
                if (value == "error")
                {
                    quit2 = true;
                }
                IncludeVar = IncludeVar.Remove(ind - 6, e - ind + 6);
                IncludeVar = IncludeVar.Insert(ind - 6, value);
                //Debug.Log(FindVariable.Substring(ind-6, e-ind+6));
                //Debug.Log("FindVariable: " + FindVariable);
                if (quit2 || blocker2 >= 64)
                {
                    break;
                }
                blocker2++;
            }



            if (IncludeVar.Replace("\t", string.Empty) == "Output.SendMail();")
            {
                SendAllMail();
            }
            else if (IncludeVar.Replace("\t", string.Empty).StartsWith("Output.SendColor") && NumberFree(SearchInString("(", ")", IncludeVar).Split(',')[1].Replace(" ", string.Empty)))
            {
                SendingMessage(SearchInString("(", ")", IncludeVar).Split(',')[1].Replace(" ", string.Empty), IncludeVar);
            }
            else if (IncludeVar.Replace("\t", string.Empty).StartsWith("Output.SendFloat") && MadeForFloat(SearchInString("(", ")", IncludeVar).Split(',')[1].Replace(" ", string.Empty)))
            {
                SendingMessage(CompileClass.ReadFloat(SearchInString("(", ")", IncludeVar).Split(',')[1].Replace(" ", string.Empty)).ToString(), IncludeVar);
            }
            else if (IncludeVar.Replace("\t", string.Empty).StartsWith("Output.SendInt") && MadeForInt(SearchInString("(", ")", IncludeVar).Split(',')[1].Replace(" ", string.Empty)))
            {
                SendingMessage(CompileClass.ReadIntegrer(SearchInString("(", ")", IncludeVar).Split(',')[1].Replace(" ", string.Empty)).ToString(), IncludeVar);
            }
            else if ((IncludeVar.Replace("\t", string.Empty).StartsWith("Output.SendFunc") || IncludeVar.Replace("\t", string.Empty).StartsWith("Output.SendString")))
            {
                SendingMessage(SearchInString("(", ")", IncludeVar).Split(',')[1].Replace(" ", string.Empty), IncludeVar);
            }
            else if (IncludeVar.Replace("\t", string.Empty).StartsWith("Output.SendBoolean"))
            {
                if (SearchInString("(", ")", IncludeVar).Split(',')[1].Replace(" ", string.Empty) == "true" || SearchInString("(", ")", IncludeVar).Split(',')[1].Replace(" ", string.Empty) == "false")
                {
                    SendingMessage(SearchInString("(", ")", IncludeVar).Split(',')[1].Replace(" ", string.Empty), IncludeVar);
                }
            }
            else if (IncludeVar.Replace("\t", string.Empty).StartsWith("Output.SendController"))
            {
                string Type;                 //Mail or Save
                string Port;                 //1 or 2 TODO: 1/2/1/2
                string Action;               //Output.
                string Data;                 //Value
                IncludeVar = SearchInString("(", ")", IncludeVar).Replace(" ", string.Empty);
                if (IncludeVar.Split(',').Length == 4)
                {
                    Type = IncludeVar.Split(',')[1];
                    //Debug.Log(IncludeVar.Split(',')[0]);
                    Port   = IncludeVar.Split(',')[0];
                    Action = IncludeVar.Split(',')[2];
                    Data   = IncludeVar.Split(',')[3];
                    //Debug.Log("I'm preparing myself to send a new mail! Here's the data:("+Port+","+Type+","+Action+","+Data+")");
                    SendingMessage(Data, Port + "," + Type + "," + Action, true);                     //"Port,Type,Action","Value"
                }
            }
        }
        else if (LineToExecute.Replace("\t", string.Empty).StartsWith("Input.Clear();"))
        {
            InputI.Data.ToList().Clear();
            InputI.DataId.ToList().Clear();
            InputI.SendFunctionMailNameI.Clear();
            InputI.SendFunctionMailValueI.Clear();
        }
        else if (LineToExecute.Replace("\t", string.Empty).StartsWith("Output.Clear();"))
        {
            OutputO.Data.ToList().Clear();
            OutputO.DataId.ToList().Clear();
            OutputO.SendFunctionMailNameI.Clear();
            OutputO.SendFunctionMailValueI.Clear();
        }
        else
        {
            if (LineToExecute.EndsWith(";") && LineToExecute.Contains(" = "))
            {
                string[] parts = LineToExecute.Replace("\t", string.Empty).Replace(";", string.Empty).Replace(" = ", "\t").Split('\t');
                //OutputO.Data[OutputO.DataId.ToList().IndexOf(parts[0])] = parts[1];
                if (OutputO.DataId.ToList().Contains(parts[0]))
                {
                    OutputO.Data[OutputO.DataId.ToList().IndexOf(parts[0])] = parts[1];
                }
                else
                {
                    Debug.Log("Fail: " + parts[0]);
                }
            }
        }
        return(0);
    }
コード例 #2
0
ファイル: Transport.cs プロジェクト: akhuang/Zing
        protected override void Serialize(IDictionary <string, object> json)
        {
            if (CustomRead != null)
            {
                json["read"] = CustomRead;
            }
            else if (FunctionRead.HasValue())
            {
                json["read"] = FunctionRead;
            }
            else
            {
                var read = Read.ToJson();
                if (read.Keys.Any())
                {
                    json["read"] = read;
                }
            }

            if (SerializeEmptyPrefix)
            {
                json["prefix"] = Prefix.HasValue() ? Prefix : string.Empty;
            }
            else if (Prefix.HasValue())
            {
                json["prefix"] = Prefix;
            }

            if (CustomUpdate != null)
            {
                json["update"] = CustomUpdate;
            }
            else if (FunctionUpdate.HasValue())
            {
                json["update"] = FunctionUpdate;
            }
            else
            {
                var update = Update.ToJson();

                if (update.Keys.Any())
                {
                    json["update"] = update;
                }
            }

            if (CustomCreate != null)
            {
                json["create"] = CustomCreate;
            }
            else if (FunctionCreate.HasValue())
            {
                json["create"] = FunctionCreate;
            }
            else
            {
                var create = Create.ToJson();

                if (create.Keys.Any())
                {
                    json["create"] = create;
                }
            }

            if (CustomDestroy != null)
            {
                json["destroy"] = CustomDestroy;
            }
            else if (FunctionDestroy.HasValue())
            {
                json["destroy"] = FunctionDestroy;
            }
            else
            {
                var destroy = Destroy.ToJson();

                if (destroy.Keys.Any())
                {
                    json["destroy"] = destroy;
                }
            }

            if (StringifyDates)
            {
                json["stringifyDates"] = StringifyDates;
            }

            if (!string.IsNullOrEmpty(IdField))
            {
                json["idField"] = IdField;
            }

            if (ParameterMap.HasValue())
            {
                json["parameterMap"] = ParameterMap;
            }

            var signalR = SignalR.ToJson();

            if (signalR.Keys.Any())
            {
                json["signalr"] = signalR;
            }
        }