Exemplo n.º 1
0
        protected static bool TryGetVariableHelper(string name, T variable, out ISledLuaVarBaseType luaVar)
        {
            luaVar = null;

            if (string.Compare(variable.Name, name, StringComparison.Ordinal) == 0)
            {
                luaVar = variable;
                return(true);
            }

            // Check if any children
            if (!variable.Variables.Any())
            {
                return(false);
            }

            // Enumerate through children
            foreach (var var in variable.Variables.Select(v => v.As <T>()))
            {
                if (TryGetVariableHelper(name, var, out luaVar))
                {
                    return(true);
                }
            }

            return(false);
        }
        public bool TryGetVariable(string name, DomNodeType nodeType, out ISledLuaVarBaseType luaVar)
        {
            luaVar = null;

            if (string.IsNullOrEmpty(name))
            {
                return(false);
            }

            if (nodeType == null)
            {
                return(false);
            }

            if (m_dictVarServices.Count <= 0)
            {
                return(false);
            }

            ISledLuaVariableService variableService;

            return
                (m_dictVarServices.TryGetValue(nodeType, out variableService) &&
                 variableService.TryGetVariable(name, out luaVar));
        }
Exemplo n.º 3
0
        public static ISledLuaVarBaseType GetRootLevelVar(ISledLuaVarBaseType luaVar)
        {
            // Lineage starts with the current node and heads
            // toward the root (instead of starting with root
            // and heading toward current node)
            var lineage = new List<DomNode>(luaVar.DomNode.Lineage);

            // Return the 2nd to last item (if any)
            return lineage.Count <= 1 ? luaVar : lineage[lineage.Count - 2].As<ISledLuaVarBaseType>();
        }
Exemplo n.º 4
0
        public static ISledLuaVarBaseType GetRootLevelVar(ISledLuaVarBaseType luaVar)
        {
            // Lineage starts with the current node and heads
            // toward the root (instead of starting with root
            // and heading toward current node)
            var lineage = new List <DomNode>(luaVar.DomNode.Lineage);

            // Return the 2nd to last item (if any)
            return(lineage.Count <= 1 ? luaVar : lineage[lineage.Count - 2].As <ISledLuaVarBaseType>());
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create lookup from a Lua variable
        /// </summary>
        /// <param name="luaVar"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public static SledLuaVarLookUpType FromLuaVar(ISledLuaVarBaseType luaVar, SledLuaVarLookUpContextType context)
        {
            try
            {
                var lookUp =
                    new DomNode(SledLuaSchema.SledLuaVarLookUpType.Type)
                    .As <SledLuaVarLookUpType>();

                lookUp.Scope   = luaVar.Scope;
                lookUp.Context = context;

                // Go through and generate a list of key/value pairs of the hierarchy so we can
                // look up and find the variable on the target no matter where it may be
                foreach (var nameAndType in luaVar.TargetHierarchy)
                {
                    lookUp.NamesAndTypes.Add((SledLuaVarNameTypePairType)nameAndType.Clone());
                }

                lookUp.NamesAndTypes.Add(SledLuaVarNameTypePairType.Create(luaVar.DisplayName, luaVar.KeyType));

                var index      = 0;
                var stackLevel = 0;

                // Some special processing if a local or upvalue variable
                if (luaVar.DomNode.Is <SledLuaVarLocalUpvalueBaseType>())
                {
                    var varTmp = luaVar.DomNode.As <SledLuaVarLocalUpvalueBaseType>();

                    stackLevel = varTmp.Level;
                    index      = varTmp.Index;
                }

                // Some special processing if an environment variable
                if (luaVar.DomNode.Is <SledLuaVarEnvType>())
                {
                    var varTmp = luaVar.DomNode.As <SledLuaVarEnvType>();

                    stackLevel = varTmp.Level;
                }

                lookUp.StackLevel = stackLevel;
                lookUp.Index      = index;

                return(lookUp);
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLineDebug(
                    SledMessageType.Error,
                    "{0}: Exception in FromLuaVar: {1}",
                    typeof(SledLuaVarLookUpType), ex.Message);

                return(null);
            }
        }
Exemplo n.º 6
0
 public SledLuaWatchedCustomVariableRendererArgs(TreeListView control, TreeListView.Node node, Graphics gfx, Rectangle bounds, int column, ISledLuaVarBaseType luaVar, SledLuaWatchedCustomVariable customVar)
 {
     Control        = control;
     Node           = node;
     Graphics       = gfx;
     Bounds         = bounds;
     Column         = column;
     LuaVariable    = luaVar;
     CustomVariable = customVar;
     DrawDefault    = true;
 }
 public SledLuaWatchedCustomVariableRendererArgs(TreeListView control, TreeListView.Node node, Graphics gfx, Rectangle bounds, int column, ISledLuaVarBaseType luaVar, SledLuaWatchedCustomVariable customVar)
 {
     Control = control;
     Node = node;
     Graphics = gfx;
     Bounds = bounds;
     Column = column;
     LuaVariable = luaVar;
     CustomVariable = customVar;
     DrawDefault = true;
 }
Exemplo n.º 8
0
        public void AddLocations(ISledLuaVarBaseType luaVar)
        {
            if (luaVar == null)
            {
                return;
            }

            Dictionary <string, List <SledLuaVariableParserService.VariableResult> > parsedVars;

            {
                var nodeType = luaVar.DomNode.Type;
                if (nodeType == SledLuaSchema.SledLuaVarLocalType.Type)
                {
                    parsedVars = m_luaVariableParserService.ParsedLocals;
                }
                else if (nodeType == SledLuaSchema.SledLuaVarUpvalueType.Type)
                {
                    parsedVars = m_luaVariableParserService.ParsedUpvalues;
                }
                else
                {
                    parsedVars = m_luaVariableParserService.ParsedGlobals;
                }
            }

            if (parsedVars == null)
            {
                return;
            }

            // No locations for variable
            List <SledLuaVariableParserService.VariableResult> items;

            if (!parsedVars.TryGetValue(luaVar.Name, out items))
            {
                return;
            }

            // Iterate through all values belonging to this key
            foreach (var result in items)
            {
                var domNode = new DomNode(SledSchema.SledVarLocationType.Type);

                // Generate location data
                var loc = domNode.As <SledVarLocationType>();

                loc.File      = result.File.AbsolutePath;
                loc.Line      = result.Line;
                loc.Occurence = result.Occurence;

                // Add to list
                luaVar.Locations.Add(loc);
            }
        }
Exemplo n.º 9
0
            private static int CompareNames(ISledLuaVarBaseType x, ISledLuaVarBaseType y)
            {
                //
                // When comparing root level watch items we don't
                // want to do the number check as two table items
                // at differing stack heights will compare as
                // equivalent (and perhaps other variable types
                // would, too).
                // For instance take the Lua table values "a.5.1"
                // and "a.5.1.1". Both of these items have the
                // same "CompareNames" result ("1" vs. "1"), the
                // same "CompareWhat" result ("LUA_TTABLE" vs.
                // "LUA_TTABLE") and the same "CompareValue" result
                // ("<table>" vs. "<table>") but they are clearly
                // not the same item! This makes the SortedList
                // used in the SledListTreeViewEditor class barf
                // when trying to set up the root node (it thinks
                // there are items with duplicate keys). So, lets
                // not do the number comparison on root level watch
                // list items!
                //

                var var1Root = x.DomNode.GetRoot();
                var var2Root = y.DomNode.GetRoot();

                var bWatchList =
                    ((var1Root.Type == SledLuaSchema.SledLuaVarWatchListType.Type) ||
                     (var2Root.Type == SledLuaSchema.SledLuaVarWatchListType.Type));

                var bWatchListRootItem =
                    bWatchList &&
                    (ReferenceEquals(x.DomNode.Parent, var1Root) ||
                     ReferenceEquals(y.DomNode.Parent, var2Root));

                double d1, d2;

                if (!bWatchListRootItem &&
                    double.TryParse(x.DisplayName, out d1) &&
                    double.TryParse(y.DisplayName, out d2))
                {
                    if (d1 == d2)
                    {
                        return(0);
                    }
                    if (d1 < d2)
                    {
                        return(-1);
                    }
                    return(1);
                }

                return(System.Globalization.SortKey.Compare(x.NameSortKey, y.NameSortKey));
            }
Exemplo n.º 10
0
        public static void SetupTargetHierarchyFromRuntimeData(ISledLuaVarBaseType luaVar, List <KeyValuePair <string, int> > hierarchy)
        {
            foreach (var kv in hierarchy)
            {
                var nameAndType =
                    new DomNode(SledLuaSchema.SledLuaVarNameTypePairType.Type)
                    .As <SledLuaVarNameTypePairType>();

                nameAndType.Name     = kv.Key;
                nameAndType.NameType = kv.Value;

                luaVar.TargetHierarchy.Add(nameAndType);
            }
        }
Exemplo n.º 11
0
        public virtual bool TryGetVariable(string name, out ISledLuaVarBaseType luaVar)
        {
            luaVar = null;

            foreach (var variable in Variables.Select(v => v.As <T>()))
            {
                if (TryGetVariableHelper(name, variable, out luaVar))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 12
0
            private static int CompareDomNodeType(ISledLuaVarBaseType x, ISledLuaVarBaseType y)
            {
                var domNodeType1 = x.DomNode.Type;
                var domNodeType2 = y.DomNode.Type;

                if (domNodeType1 == domNodeType2)
                {
                    return(0);
                }

                var nodeType1 = domNodeType1.ToString();
                var nodeType2 = domNodeType2.ToString();

                return(string.Compare(nodeType1, nodeType2, StringComparison.Ordinal));
            }
        /// <summary>
        /// Create project watch from Lua variable
        /// </summary>
        /// <param name="luaVar"></param>
        /// <returns></returns>
        public static SledLuaProjectFilesWatchType CreateFromLuaVar(ISledLuaVarBaseType luaVar)
        {
            var projectFilesWatch =
                new DomNode(SledLuaSchema.SledLuaProjectFilesWatchType.Type)
                .As <SledLuaProjectFilesWatchType>();

            var luaLanguagePlugin = SledServiceInstance.TryGet <SledLuaLanguagePlugin>();

            projectFilesWatch.Name           = luaVar.DisplayName;
            projectFilesWatch.LanguagePlugin = luaLanguagePlugin;
            projectFilesWatch.Scope          = luaVar.Scope;
            projectFilesWatch.Context        = SledLuaVarLookUpContextType.WatchProject;
            projectFilesWatch.LookUp         = SledLuaVarLookUpType.FromLuaVar(luaVar, projectFilesWatch.Context);

            return(projectFilesWatch);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Create project watch from Lua variable
        /// </summary>
        /// <param name="luaVar"></param>
        /// <returns></returns>
        public static SledLuaProjectFilesWatchType CreateFromLuaVar(ISledLuaVarBaseType luaVar)
        {
            var projectFilesWatch =
                new DomNode(SledLuaSchema.SledLuaProjectFilesWatchType.Type)
                    .As<SledLuaProjectFilesWatchType>();

            var luaLanguagePlugin = SledServiceInstance.TryGet<SledLuaLanguagePlugin>();

            projectFilesWatch.Name = luaVar.DisplayName;
            projectFilesWatch.LanguagePlugin = luaLanguagePlugin;
            projectFilesWatch.Scope = luaVar.Scope;
            projectFilesWatch.Context = SledLuaVarLookUpContextType.WatchProject;
            projectFilesWatch.LookUp = SledLuaVarLookUpType.FromLuaVar(luaVar, projectFilesWatch.Context);

            return projectFilesWatch;
        }
Exemplo n.º 15
0
        /// <summary>
        /// Returns true if a variable is [locally] filtered by name or by LUA_T&lt;type&gt;
        /// </summary>
        /// <param name="luaVar">Variable to check</param>
        /// <returns>True if variable is [locally] filtered by name or by LUA_T&lt;type&gt; and false if not</returns>
        public bool IsVariableFiltered(ISledLuaVarBaseType luaVar)
        {
            if (luaVar == null)
            {
                return(false);
            }

            SledLuaVariableFilterState filterState = null;
            var nodeType = luaVar.DomNode.Type;

            if (nodeType == SledLuaSchema.SledLuaVarGlobalType.Type)
            {
                filterState = m_globalVariableFilterState;
            }
            else if (nodeType == SledLuaSchema.SledLuaVarLocalType.Type)
            {
                filterState = m_localVariableFilterState;
            }
            else if (nodeType == SledLuaSchema.SledLuaVarUpvalueType.Type)
            {
                filterState = m_upvalueVariableFilterState;
            }
            else if (nodeType == SledLuaSchema.SledLuaVarEnvType.Type)
            {
                filterState = m_envVarVariableFilterState;
            }

            if (filterState == null)
            {
                return(false);
            }

            // Check if type is filtered
            if (filterState.LocalFilterTypes[SledLuaUtil.LuaTypeStringToInt(luaVar.What)])
            {
                return(true);
            }

            // Check if name is filtered
            if (VarNameFiltered(luaVar.Name, filterState.LocalFilterNames))
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 16
0
        public bool TryGetVariable(string name, DomNodeType nodeType, out ISledLuaVarBaseType luaVar)
        {
            luaVar = null;

            if (string.IsNullOrEmpty(name))
                return false;

            if (nodeType == null)
                return false;

            if (m_dictVarServices.Count <= 0)
                return false;

            ISledLuaVariableService variableService;
            return
                m_dictVarServices.TryGetValue(nodeType, out variableService) &&
                variableService.TryGetVariable(name, out luaVar);
        }
Exemplo n.º 17
0
            private static int CompareValue(ISledLuaVarBaseType x, ISledLuaVarBaseType y)
            {
                double d1, d2;

                if (double.TryParse(x.Value, out d1) &&
                    double.TryParse(y.Value, out d2))
                {
                    if (d1 == d2)
                    {
                        return(0);
                    }
                    if (d1 < d2)
                    {
                        return(-1);
                    }
                    return(1);
                }

                return(System.Globalization.SortKey.Compare(x.ValueSortKey, y.ValueSortKey));
            }
Exemplo n.º 18
0
        public void AddLocations(ISledLuaVarBaseType luaVar)
        {
            if (luaVar == null)
                return;

            Dictionary<string, List<SledLuaVariableParserService.VariableResult>> parsedVars;

            {
                var nodeType = luaVar.DomNode.Type;
                if (nodeType == SledLuaSchema.SledLuaVarLocalType.Type)
                    parsedVars = m_luaVariableParserService.ParsedLocals;
                else if (nodeType == SledLuaSchema.SledLuaVarUpvalueType.Type)
                    parsedVars = m_luaVariableParserService.ParsedUpvalues;
                else
                    parsedVars = m_luaVariableParserService.ParsedGlobals;
            }

            if (parsedVars == null)
                return;

            // No locations for variable
            List<SledLuaVariableParserService.VariableResult> items;
            if (!parsedVars.TryGetValue(luaVar.Name, out items))
                return;

            // Iterate through all values belonging to this key
            foreach (var result in items)
            {
                var domNode = new DomNode(SledSchema.SledVarLocationType.Type);

                // Generate location data
                var loc = domNode.As<SledVarLocationType>();

                loc.File = result.File.AbsolutePath;
                loc.Line = result.Line;
                loc.Occurence = result.Occurence;

                // Add to list
                luaVar.Locations.Add(loc);
            }
        }
Exemplo n.º 19
0
        private static bool TryGetLuaVar(IDataObject dataObject, out ISledLuaVarBaseType luaVar)
        {
            luaVar = null;

            if (dataObject == null)
            {
                return(false);
            }

            try
            {
                if (dataObject.GetDataPresent(typeof(SledLuaVarGlobalType)))
                {
                    luaVar = (SledLuaVarGlobalType)dataObject.GetData(typeof(SledLuaVarGlobalType));
                }
                else if (dataObject.GetDataPresent(typeof(SledLuaVarLocalType)))
                {
                    luaVar = (SledLuaVarLocalType)dataObject.GetData(typeof(SledLuaVarLocalType));
                }
                else if (dataObject.GetDataPresent(typeof(SledLuaVarUpvalueType)))
                {
                    luaVar = (SledLuaVarUpvalueType)dataObject.GetData(typeof(SledLuaVarUpvalueType));
                }
                else if (dataObject.GetDataPresent(typeof(SledLuaVarEnvType)))
                {
                    luaVar = (SledLuaVarEnvType)dataObject.GetData(typeof(SledLuaVarEnvType));
                }
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLine(
                    SledMessageType.Error,
                    "[Variable List] Exception with drag-and-drop: {0}",
                    ex.Message);
            }

            return(luaVar != null);
        }
Exemplo n.º 20
0
        protected virtual bool OnTryGetVariable(string name, out ISledLuaVarBaseType luaVar)
        {
            luaVar = null;

            return(Collection.Count > 0 && Collection[0].TryGetVariable(name, out luaVar));
        }
Exemplo n.º 21
0
 private static int CompareWhat(ISledLuaVarBaseType x, ISledLuaVarBaseType y)
 {
     return(System.Globalization.SortKey.Compare(x.WhatSortKey, y.WhatSortKey));
 }
Exemplo n.º 22
0
        /// <summary>
        /// Returns true if a variable is [locally] filtered by name or by LUA_T&lt;type&gt;
        /// </summary>
        /// <param name="luaVar">Variable to check</param>
        /// <returns>True if variable is [locally] filtered by name or by LUA_T&lt;type&gt; and false if not</returns>
        public bool IsVariableFiltered(ISledLuaVarBaseType luaVar)
        {
            if (luaVar == null)
                return false;

            SledLuaVariableFilterState filterState = null;
            var nodeType = luaVar.DomNode.Type;

            if (nodeType == SledLuaSchema.SledLuaVarGlobalType.Type)
                filterState = m_globalVariableFilterState;
            else if (nodeType == SledLuaSchema.SledLuaVarLocalType.Type)
                filterState = m_localVariableFilterState;
            else if (nodeType == SledLuaSchema.SledLuaVarUpvalueType.Type)
                filterState = m_upvalueVariableFilterState;
            else if (nodeType == SledLuaSchema.SledLuaVarEnvType.Type)
                filterState = m_envVarVariableFilterState;

            if (filterState == null)
                return false;

            // Check if type is filtered
            if (filterState.LocalFilterTypes[SledLuaUtil.LuaTypeStringToInt(luaVar.What)])
                return true;

            // Check if name is filtered
            if (VarNameFiltered(luaVar.Name, filterState.LocalFilterNames))
                return true;

            return false;
        }
Exemplo n.º 23
0
        public static void SetupTargetHierarchyFromRuntimeData(ISledLuaVarBaseType luaVar, List<KeyValuePair<string, int>> hierarchy)
        {
            foreach (var kv in hierarchy)
            {
                var nameAndType =
                    new DomNode(SledLuaSchema.SledLuaVarNameTypePairType.Type)
                    .As<SledLuaVarNameTypePairType>();

                nameAndType.Name = kv.Key;
                nameAndType.NameType = kv.Value;

                luaVar.TargetHierarchy.Add(nameAndType);
            }
        }
Exemplo n.º 24
0
 public static bool IsEditableLuaType(ISledLuaVarBaseType luaVar)
 {
     return IsEditableLuaType(luaVar.LuaType) && IsEditableLuaType((LuaType)luaVar.KeyType);
 }
Exemplo n.º 25
0
 public bool TryGetVariable(string name, out ISledLuaVarBaseType luaVar)
 {
     return(OnTryGetVariable(name, out luaVar));
 }
Exemplo n.º 26
0
        /// <summary>
        /// Create lookup from a Lua variable
        /// </summary>
        /// <param name="luaVar"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public static SledLuaVarLookUpType FromLuaVar(ISledLuaVarBaseType luaVar, SledLuaVarLookUpContextType context)
        {
            try
            {
                var lookUp =
                    new DomNode(SledLuaSchema.SledLuaVarLookUpType.Type)
                    .As<SledLuaVarLookUpType>();

                lookUp.Scope = luaVar.Scope;
                lookUp.Context = context;

                // Go through and generate a list of key/value pairs of the hierarchy so we can
                // look up and find the variable on the target no matter where it may be
                foreach (var nameAndType in luaVar.TargetHierarchy)
                    lookUp.NamesAndTypes.Add((SledLuaVarNameTypePairType)nameAndType.Clone());

                lookUp.NamesAndTypes.Add(SledLuaVarNameTypePairType.Create(luaVar.DisplayName, luaVar.KeyType));

                var index = 0;
                var stackLevel = 0;

                // Some special processing if a local or upvalue variable
                if (luaVar.DomNode.Is<SledLuaVarLocalUpvalueBaseType>())
                {
                    var varTmp = luaVar.DomNode.As<SledLuaVarLocalUpvalueBaseType>();

                    stackLevel = varTmp.Level;
                    index = varTmp.Index;
                }

                // Some special processing if an environment variable
                if (luaVar.DomNode.Is<SledLuaVarEnvType>())
                {
                    var varTmp = luaVar.DomNode.As<SledLuaVarEnvType>();

                    stackLevel = varTmp.Level;
                }

                lookUp.StackLevel = stackLevel;
                lookUp.Index = index;

                return lookUp;
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLineDebug(
                    SledMessageType.Error,
                    "{0}: Exception in FromLuaVar: {1}",
                    typeof(SledLuaVarLookUpType), ex.Message);

                return null;
            }
        }
Exemplo n.º 27
0
 public static bool IsEditableLuaType(ISledLuaVarBaseType luaVar)
 {
     return(IsEditableLuaType(luaVar.LuaType) && IsEditableLuaType((LuaType)luaVar.KeyType));
 }