From a47f89582b8a66776ad8b56da8e19233c621d8e1 Mon Sep 17 00:00:00 2001 From: adelikat Date: Mon, 6 Apr 2020 17:12:16 -0500 Subject: [PATCH] LuaDeprecatedMethod - documentation generation failed to filter it out, instead though mark it as depcreated in documentation, Lua functions list - fix column sorting, simplifications --- BizHawk.Client.Common/lua/LuaDocumentation.cs | 14 ++--- .../tools/Lua/LuaFunctionsForm.cs | 56 +++++-------------- 2 files changed, 21 insertions(+), 49 deletions(-) diff --git a/BizHawk.Client.Common/lua/LuaDocumentation.cs b/BizHawk.Client.Common/lua/LuaDocumentation.cs index 473c0c2bfc..3769c2bf99 100644 --- a/BizHawk.Client.Common/lua/LuaDocumentation.cs +++ b/BizHawk.Client.Common/lua/LuaDocumentation.cs @@ -40,7 +40,7 @@ __Types and notation__ ** A standard Lua table "); - foreach (var library in this.Where(lf => !lf.IsDeprecated).Select(lf => new { Name = lf.Library, Description = lf.LibraryDescription }).Distinct()) + foreach (var library in this.Select(lf => new { Name = lf.Library, Description = lf.LibraryDescription }).Distinct()) { sb .AppendFormat("%%TAB {0}%%", library.Name) @@ -56,10 +56,11 @@ __Types and notation__ foreach (var func in this.Where(lf => lf.Library == library.Name)) { + string deprecated = func.IsDeprecated ? "__[[deprecated]]__ " : ""; sb .AppendFormat("__{0}.{1}__%%%", func.Library, func.Name) .AppendLine().AppendLine() - .AppendFormat("* {0} {1}.{2}{3}", func.ReturnType, func.Library, func.Name, func.ParameterList.Replace("[", "[[").Replace("]", "]]")) + .AppendFormat("* {4}{0} {1}.{2}{3}", func.ReturnType, func.Library, func.Name, func.ParameterList.Replace("[", "[[").Replace("]", "]]"), deprecated) .AppendLine().AppendLine() .AppendFormat("* {0}", func.Description) .AppendLine().AppendLine(); @@ -158,13 +159,12 @@ __Types and notation__ { private readonly LuaMethodAttribute _luaAttributes; private readonly LuaMethodExampleAttribute _luaExampleAttribute; - private readonly MethodInfo _method; public LibraryFunction(string library, string libraryDescription, MethodInfo method) { _luaAttributes = method.GetCustomAttribute(false); _luaExampleAttribute = method.GetCustomAttribute(false); - _method = method; + Method = method; IsDeprecated = method.GetCustomAttribute(false) != null; Library = library; @@ -176,7 +176,7 @@ __Types and notation__ public readonly bool IsDeprecated; - public MethodInfo Method => _method; + public MethodInfo Method { get; } public string Name => _luaAttributes.Name; @@ -192,7 +192,7 @@ __Types and notation__ { if (_parameterList == null) { - var parameters = _method.GetParameters(); + var parameters = Method.GetParameters(); var list = new StringBuilder(); list.Append('('); @@ -259,7 +259,7 @@ __Types and notation__ { get { - var returnType = _method.ReturnType.ToString(); + var returnType = Method.ReturnType.ToString(); return TypeCleanup(returnType).Trim(); } } diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaFunctionsForm.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaFunctionsForm.cs index a516856712..df66e39494 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaFunctionsForm.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaFunctionsForm.cs @@ -5,6 +5,7 @@ using System.Text; using System.Windows.Forms; using BizHawk.Client.Common; +using BizHawk.Common.CollectionExtensions; namespace BizHawk.Client.EmuHawk { @@ -54,7 +55,9 @@ namespace BizHawk.Client.EmuHawk var entry = _filteredList[e.ItemIndex]; e.Item = new ListViewItem(entry.ReturnType); e.Item.SubItems.Add(entry.Library); - e.Item.SubItems.Add(entry.Name); + + var deprecated = entry.IsDeprecated ? "[Deprecated] " : ""; + e.Item.SubItems.Add(deprecated + entry.Name); e.Item.SubItems.Add(entry.ParameterList); e.Item.SubItems.Add(entry.Description); } @@ -62,48 +65,16 @@ namespace BizHawk.Client.EmuHawk private void OrderColumn(int column) { _columnSort.Column = column; - if (_columnSort.Descending) + + _functionList = column switch { - switch (column) - { - case 0: // Return - _functionList = _functionList.OrderByDescending(x => x.ReturnType).ToList(); - break; - case 1: // Library - _functionList = _functionList.OrderByDescending(x => x.Library).ToList(); - break; - case 2: // Name - _functionList = _functionList.OrderByDescending(x => x.Name).ToList(); - break; - case 3: // Parameters - _functionList = _functionList.OrderByDescending(x => x.ParameterList).ToList(); - break; - case 4: // Description - _functionList = _functionList.OrderByDescending(x => x.Description).ToList(); - break; - } - } - else - { - switch (column) - { - case 0: // Return - _functionList = _functionList.OrderBy(x => x.ReturnType).ToList(); - break; - case 1: // Library - _functionList = _functionList.OrderBy(x => x.Library).ToList(); - break; - case 2: // Name - _functionList = _functionList.OrderBy(x => x.Name).ToList(); - break; - case 3: // Parameters - _functionList = _functionList.OrderBy(x => x.ParameterList).ToList(); - break; - case 4: // Description - _functionList = _functionList.OrderBy(x => x.Description).ToList(); - break; - } - } + 0 => _functionList.OrderBy(x => x.ReturnType, _columnSort.Descending).ToList(), + 1 => _functionList.OrderBy(x => x.Library, _columnSort.Descending).ToList(), + 2 => _functionList.OrderBy(x => x.Name, _columnSort.Descending).ToList(), + 3 => _functionList.OrderBy(x => x.ParameterList, _columnSort.Descending).ToList(), + 4 => _functionList.OrderBy(x => x.Description, _columnSort.Descending).ToList(), + _ => _functionList + }; UpdateList(); } @@ -176,6 +147,7 @@ namespace BizHawk.Client.EmuHawk { GenerateFilteredList(); FunctionView.VirtualListSize = _filteredList.Count; + FunctionView.Refresh(); } private void FilterBox_KeyUp(object sender, KeyEventArgs e)