예제 #1
0
        private void tlvwLocals_ItemAfterEdit(object sender, TreeListViewAfterEditEventArgs e)
        {
            if (e.Item != null && (e.SubItem != null && e.Item.Tag is LuaVariable) && e.SubItem.Text != e.NewValue)
            {
                LuaVariable oldVar     = e.Item.Tag as LuaVariable;
                LuaVariable updatedVar = new LuaVariable();
                double      dummyDouble;

                if (e.NewValue.StartsWith("\""))
                {
                    string strVal = e.NewValue.Substring(1);
                    // Let's consider the new value a string
                    if (e.NewValue.EndsWith("\""))
                    {
                        strVal = strVal.Substring(0, strVal.Length - 1);
                    }

                    updatedVar.Type  = LuaTypes.LUA_TSTRING;
                    updatedVar.Value = strVal;
                }
                else if (Double.TryParse(e.NewValue, out dummyDouble))
                {
                    updatedVar.Type  = LuaTypes.LUA_TNUMBER;
                    updatedVar.Value = string.Format("{0:0.000000}", Convert.ToDouble(e.NewValue));
                }
                else if (e.NewValue.ToLower() == "nil")
                {
                    updatedVar.Type  = LuaTypes.LUA_TNIL;
                    updatedVar.Value = e.NewValue.ToLower();
                }
                else if (e.NewValue.StartsWith("{"))
                {
                    // todo: handle table construct by executing "return {...}" and
                    //       setting the result of execution as the local's value
                }
                else
                {
                    updatedVar.Type  = LuaTypes.LUA_TSTRING;
                    updatedVar.Value = e.NewValue;
                }

                updatedVar.Index       = oldVar.Index;
                updatedVar.FullNameOut = oldVar.FullNameOut;
                updatedVar.Name        = oldVar.Name;

                if (oldVar.Type == LuaTypes.LUA_TTABLE && updatedVar.Type != LuaTypes.LUA_TTABLE)
                {
                    // Remove all child
                    TreeListViewItem tlvi = _nodesByFullName[oldVar.FullNameIn];
                    RemoveTreeListViewItemChildsRecursively(tlvi);
                }

                e.Item.Tag = updatedVar;
                e.Item.SubItems[0].Object = updatedVar.Name;
                e.Item.SubItems[1].Object = updatedVar.GetPrettyPrintValue();
                e.Item.SubItems[2].Object = updatedVar.Type.ToString();

                ClientDebugManager.Instance.AddCommand(new SetLuaVariableCommand(updatedVar));
            }
        }
예제 #2
0
        public void DeserializeData(byte[] data, ref int offset)
        {
            IRPCSerializableData tempLuaVar = null;

            DeserializeComplexData(data, ref offset, ref tempLuaVar, typeof(LuaVariable));
            LuaVar = tempLuaVar as LuaVariable;
        }
예제 #3
0
 private void tlvwLocals_ItemExpanding(object sender, TreeListViewCancelEventArgs e)
 {
     if (e.Item.Items.Count == 1 && e.Item.Items[0].Text == EmptyTableElementName)
     {
         LuaVariable var = e.Item.Tag as LuaVariable;
         ClientDebugManager.Instance.AddCommand(new UpdateTableDetailsCommand(var.FullNameIn, var.FullNameOut, true, null));
     }
 }
예제 #4
0
 private void tlvwLocals_ItemBeforeEdit(object sender, TreeListViewBeforeEditEventArgs e)
 {
     if (ClientDebugManager.Instance.IsBreaked &&
         e.SubItem != null && (e.Item != null && e.Item.Tag is LuaVariable))
     {
         LuaVariable editedVar = e.Item.Tag as LuaVariable;
         TextBox     editor    = new TextBox();
         editor.BorderStyle = BorderStyle.None;
         e.Editor           = editor;
         e.DefaultValue     = editedVar.Type == LuaTypes.LUA_TSTRING ? string.Format("\"{0}\"", editedVar.GetPrettyPrintValue()) : editedVar.GetPrettyPrintValue();
     }
 }
예제 #5
0
        private TreeListViewItem LuaVariableToTreeListViewItem(LuaVariable luaVar)
        {
            // Create main item with name
            TreeListViewItem tlvi = new TreeListViewItem(luaVar.Name);

            tlvi.Tag = luaVar;

            // Create subitem with value
            TreeListViewSubItem tlvsi = new TreeListViewSubItem(1, luaVar.GetPrettyPrintValue());

            tlvsi.Tag = luaVar.Value;
            tlvi.SubItems.Add(tlvsi);

            // Create subitem with value type
            tlvsi = new TreeListViewSubItem(2, luaVar.Type.ToString());
            tlvi.SubItems.Add(tlvsi);

            if (luaVar.Type == LuaTypes.LUA_TTABLE)
            {
                tlvi.Items.Add(EmptyTableElementName);
            }

            return(tlvi);
        }
예제 #6
0
        private void UpdateVariables(TreeListViewItem parentItem, List <LuaVariable> currentVars)
        {
            int nonDirtyVarsCount = 0;

            // Remove fake node
            if (parentItem.Items.Count == 1 && parentItem.Items[0].Tag == null)
            {
                parentItem.Items.Remove(parentItem.Items[0]);
            }

            for (int x = parentItem.Items.Count - 1; x >= 0; --x)
            {
                TreeListViewItem tlvi   = parentItem.Items[x];
                LuaVariable      luaVar = tlvi.Tag as LuaVariable;

                if (luaVar != null)
                {
                    _searchingVar = luaVar;
                    LuaVariable updatedVar = currentVars.Find(FindLocalPredicate);

                    if (updatedVar != null && updatedVar.Name != LuaVariable.TemporaryName)
                    {
                        // The local variable still exists, let's see if
                        // its type or value has changed and if so, let's
                        // update it
                        updatedVar.IsDirty = false;
                        ++nonDirtyVarsCount;

                        if (updatedVar.Value != luaVar.Value || updatedVar.Type != luaVar.Type)
                        {
                            tlvi.Tag = updatedVar;
                            tlvi.SubItems[1].Object    = updatedVar.GetPrettyPrintValue();
                            tlvi.SubItems[1].ForeColor = Color.Red;
                            tlvi.SubItems[2].Object    = updatedVar.Type.ToString();
                            tlvi.SubItems[2].ForeColor = Color.Red;
                        }
                        else
                        {
                            tlvi.SubItems[1].ForeColor = Color.Empty;
                            tlvi.SubItems[2].ForeColor = Color.Empty;
                        }

                        // The local variable was a table (and is still one) and was expanded so let's
                        // update its content as well
                        if (luaVar.Type == LuaTypes.LUA_TTABLE && updatedVar.Type == LuaTypes.LUA_TTABLE &&
                            tlvi.Expanded)
                        {
                            int stackLevel = ClientDebugManager.Instance.IsInError ? 1 : 0;
                            ClientDebugManager.Instance.AddCommand(
                                new UpdateTableDetailsCommand(luaVar.FullNameIn, luaVar.FullNameOut, true, null));
                        }
                    }
                    else
                    {
                        // The local variable in not a local variable anymore
                        // so let's remove it from the list
                        RemoveTreeListViewItemChildsRecursively(tlvi);
                        _nodesByFullName.Remove(luaVar.FullNameIn);
                        parentItem.Items.Remove(tlvi);
                    }
                }
            }

            if (currentVars.Count != nonDirtyVarsCount)
            {
                foreach (LuaVariable var in currentVars)
                {
                    if (var.IsDirty)
                    {
                        TreeListViewItem tlvi = LuaVariableToTreeListViewItem(var);
                        var.IsDirty = false;
                        _nodesByFullName.Add(var.FullNameIn, tlvi);
                        parentItem.Items.Add(tlvi);
                    }
                }
            }
        }
예제 #7
0
 private bool FindLocalPredicate(LuaVariable var)
 {
     return(_searchingVar.FullNameOut == var.FullNameOut);
 }
예제 #8
0
 public SetLuaVariableCommand(LuaVariable luaVar)
     : base((int)RpcCommandType.eRPC_COMMANDTYPE_SETLUAVARIABLE)
 {
     LuaVar = luaVar;
 }
예제 #9
0
        private void OnLuaExplain()
        {
            _variables = new List <LuaVariable>();
            _functions = new List <LuaFunction>();
            StringBuilder builder = new StringBuilder();

            string[] codes = Target.text.Split(Environment.NewLine.ToCharArray());
            for (int i = 0; i < codes.Length; i++)
            {
                codes[i] = codes[i].Trim();
                if (string.IsNullOrEmpty(codes[i]) || codes[i] == "")
                {
                    continue;
                }

                //多行注释
                if (codes[i].StartsWith(_noteStart))
                {
                    if (codes[i].EndsWith(_noteEnd))
                    {
                        continue;
                    }
                    else
                    {
                        int j = i + 1;
                        for (; j < codes.Length; j++)
                        {
                            if (codes[j].StartsWith(_noteEnd))
                            {
                                break;
                            }
                        }
                        i = j;
                        continue;
                    }
                }

                //单行注释
                if (codes[i].StartsWith(_note))
                {
                    continue;
                }

                //标记局部
                bool isLocal = codes[i].StartsWith(_local);
                if (isLocal)
                {
                    codes[i] = codes[i].Remove(0, 5).TrimStart();
                }

                //标记方法
                bool isFunction = codes[i].StartsWith(_function);
                if (isFunction)
                {
                    codes[i] = codes[i].Remove(0, 8).TrimStart();
                    LuaFunction function = new LuaFunction();
                    function.Name = codes[i];
                    if (isLocal)
                    {
                        function.Name = "local " + function.Name;
                    }
                    int endCount = 0;
                    builder.Clear();
                    int j = i + 1;
                    for (; j < codes.Length; j++)
                    {
                        codes[j] = codes[j].Trim();
                        if (string.IsNullOrEmpty(codes[j]) || codes[j] == "")
                        {
                            continue;
                        }

                        if (codes[j].StartsWith(_end))
                        {
                            if (endCount > 0)
                            {
                                endCount -= 1;
                                builder.Append(codes[j]);
                                builder.Append(Environment.NewLine);
                            }
                            else
                            {
                                break;
                            }
                        }
                        else
                        {
                            if (codes[j].StartsWith(_if) || codes[j].StartsWith(_for) || codes[j].StartsWith(_while))
                            {
                                endCount += 1;
                            }
                            builder.Append(codes[j]);
                            builder.Append(Environment.NewLine);
                        }
                    }
                    i             = j;
                    function.Body = builder.ToString().Trim();
                    _functions.Add(function);
                }
                //标记变量
                else
                {
                    string[] keyValue = codes[i].Split('=');
                    if (keyValue.Length == 2)
                    {
                        string[] keys   = keyValue[0].Split(',');
                        string[] values = keyValue[1].Split(',');
                        for (int j = 0; j < keys.Length; j++)
                        {
                            LuaVariable variable = new LuaVariable();
                            variable.Name = keys[j];
                            if (isLocal)
                            {
                                variable.Name = "local " + variable.Name;
                            }
                            variable.Value = j < values.Length ? values[j] : "nil";
                            _variables.Add(variable);
                        }
                    }
                }
            }
        }