Refactor the LuaDocumentation class to remove a bunch of unnecessary stuff
This commit is contained in:
parent
bb1b1ff5b5
commit
ba4e7d620b
|
@ -5,132 +5,96 @@ using System.Text;
|
||||||
|
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
public interface ILuaDocumentation
|
public class LuaDocumentation : List<LibraryFunction>
|
||||||
{
|
|
||||||
void Add(string methodLib, string methodName, MethodInfo method, string description);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class LuaDocumentation : ILuaDocumentation
|
|
||||||
{
|
{
|
||||||
public LuaDocumentation()
|
public LuaDocumentation()
|
||||||
|
:base() { }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LibraryFunction
|
||||||
|
{
|
||||||
|
private readonly string _returnType = string.Empty;
|
||||||
|
|
||||||
|
public LibraryFunction(string methodLib, string methodName, MethodInfo method, string description)
|
||||||
{
|
{
|
||||||
FunctionList = new List<LibraryFunction>();
|
Library = methodLib;
|
||||||
}
|
Name = methodName;
|
||||||
|
var info = method.GetParameters();
|
||||||
|
|
||||||
public List<LibraryFunction> FunctionList { get; set; }
|
Parameters = new List<string>();
|
||||||
|
foreach (var p in info)
|
||||||
public void Add(string methodLib, string methodName, MethodInfo method, string description)
|
|
||||||
{
|
|
||||||
FunctionList.Add(
|
|
||||||
new LibraryFunction(methodLib, methodName, method, description));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Clear()
|
|
||||||
{
|
|
||||||
FunctionList = new List<LibraryFunction>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Sort()
|
|
||||||
{
|
|
||||||
FunctionList = FunctionList.OrderBy(x => x.Library).ThenBy(x => x.Name).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<string> GetLibraryList()
|
|
||||||
{
|
|
||||||
return FunctionList.Select(x => x.Library);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<LibraryFunction> GetFunctionsByLibrary(string library)
|
|
||||||
{
|
|
||||||
return FunctionList
|
|
||||||
.Where(func => func.Library == library);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class LibraryFunction
|
|
||||||
{
|
|
||||||
private readonly string _returnType = string.Empty;
|
|
||||||
|
|
||||||
public LibraryFunction(string methodLib, string methodName, MethodInfo method, string description)
|
|
||||||
{
|
{
|
||||||
Library = methodLib;
|
Parameters.Add(p.ToString());
|
||||||
Name = methodName;
|
|
||||||
var info = method.GetParameters();
|
|
||||||
|
|
||||||
Parameters = new List<string>();
|
|
||||||
foreach (var p in info)
|
|
||||||
{
|
|
||||||
Parameters.Add(p.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
this._returnType = method.ReturnType.ToString();
|
|
||||||
|
|
||||||
Description = description;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Library { get; set; }
|
_returnType = method.ReturnType.ToString();
|
||||||
public string Name { get; set; }
|
|
||||||
public List<string> Parameters { get; set; }
|
|
||||||
|
|
||||||
public string Description { get; set; }
|
Description = description;
|
||||||
|
}
|
||||||
|
|
||||||
public string ParameterList
|
public string Library { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public List<string> Parameters { get; set; }
|
||||||
|
|
||||||
|
public string Description { get; set; }
|
||||||
|
|
||||||
|
public string ParameterList
|
||||||
|
{
|
||||||
|
get
|
||||||
{
|
{
|
||||||
get
|
var list = new StringBuilder();
|
||||||
|
list.Append('(');
|
||||||
|
for (var i = 0; i < Parameters.Count; i++)
|
||||||
{
|
{
|
||||||
var list = new StringBuilder();
|
var param =
|
||||||
list.Append('(');
|
Parameters[i].Replace("System", string.Empty)
|
||||||
for (var i = 0; i < Parameters.Count; i++)
|
.Replace(" ", string.Empty)
|
||||||
|
.Replace(".", string.Empty)
|
||||||
|
.Replace("LuaInterface", string.Empty)
|
||||||
|
.Replace("Object[]", "object[] ")
|
||||||
|
.Replace("Object", "object ")
|
||||||
|
.Replace("Boolean[]", "bool[] ")
|
||||||
|
.Replace("Boolean", "bool ")
|
||||||
|
.Replace("String", "string ")
|
||||||
|
.Replace("LuaTable", "table ")
|
||||||
|
.Replace("LuaFunction", "func ")
|
||||||
|
.Replace("Nullable`1[Int32]", "int? ")
|
||||||
|
.Replace("Nullable`1[UInt32]", "uint? ")
|
||||||
|
.Replace("Byte", "byte ")
|
||||||
|
.Replace("Int16", "short ")
|
||||||
|
.Replace("Int32", "int ")
|
||||||
|
.Replace("Int64", "long ")
|
||||||
|
.Replace("Ushort", "ushort ")
|
||||||
|
.Replace("Ulong", "ulong ")
|
||||||
|
.Replace("UInt32", "uint ")
|
||||||
|
.Replace("UInt64", "ulong ")
|
||||||
|
.Replace("Double", "double ")
|
||||||
|
.Replace("Uint", "uint ")
|
||||||
|
.Replace("Nullable`1[DrawingColor]", "Color? ")
|
||||||
|
.Replace("DrawingColor", "Color ");
|
||||||
|
|
||||||
|
list.Append(param);
|
||||||
|
if (i < Parameters.Count - 1)
|
||||||
{
|
{
|
||||||
var param =
|
list.Append(", ");
|
||||||
Parameters[i].Replace("System", string.Empty)
|
|
||||||
.Replace(" ", string.Empty)
|
|
||||||
.Replace(".", string.Empty)
|
|
||||||
.Replace("LuaInterface", string.Empty)
|
|
||||||
.Replace("Object[]", "object[] ")
|
|
||||||
.Replace("Object", "object ")
|
|
||||||
.Replace("Boolean[]", "bool[] ")
|
|
||||||
.Replace("Boolean", "bool ")
|
|
||||||
.Replace("String", "string ")
|
|
||||||
.Replace("LuaTable", "table ")
|
|
||||||
.Replace("LuaFunction", "func ")
|
|
||||||
.Replace("Nullable`1[Int32]", "int? ")
|
|
||||||
.Replace("Nullable`1[UInt32]", "uint? ")
|
|
||||||
.Replace("Byte", "byte ")
|
|
||||||
.Replace("Int16", "short ")
|
|
||||||
.Replace("Int32", "int ")
|
|
||||||
.Replace("Int64", "long ")
|
|
||||||
.Replace("Ushort", "ushort ")
|
|
||||||
.Replace("Ulong", "ulong ")
|
|
||||||
.Replace("UInt32", "uint ")
|
|
||||||
.Replace("UInt64", "ulong ")
|
|
||||||
.Replace("Double", "double ")
|
|
||||||
.Replace("Uint", "uint ")
|
|
||||||
.Replace("Nullable`1[DrawingColor]", "Color? ")
|
|
||||||
.Replace("DrawingColor", "Color ");
|
|
||||||
|
|
||||||
list.Append(param);
|
|
||||||
if (i < Parameters.Count - 1)
|
|
||||||
{
|
|
||||||
list.Append(", ");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
list.Append(')');
|
|
||||||
|
|
||||||
return list.ToString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list.Append(')');
|
||||||
|
|
||||||
|
return list.ToString();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string ReturnType
|
public string ReturnType
|
||||||
|
{
|
||||||
|
get
|
||||||
{
|
{
|
||||||
get
|
return _returnType
|
||||||
{
|
.Replace("System.", string.Empty)
|
||||||
return _returnType
|
.Replace("LuaInterface.", string.Empty)
|
||||||
.Replace("System.", string.Empty)
|
.ToLower()
|
||||||
.Replace("LuaInterface.", string.Empty)
|
.Trim();
|
||||||
.ToLower()
|
|
||||||
.Trim();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace BizHawk.Client.Common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void LuaRegister(ILuaDocumentation docs = null)
|
public virtual void LuaRegister(LuaDocumentation docs = null)
|
||||||
{
|
{
|
||||||
Lua.NewTable(Name);
|
Lua.NewTable(Name);
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
if (docs != null)
|
if (docs != null)
|
||||||
{
|
{
|
||||||
docs.Add(Name, luaMethodAttr.Name, method, luaMethodAttr.Description);
|
docs.Add(new LibraryFunction(Name, luaMethodAttr.Name, method, luaMethodAttr.Description));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
public static string GetLuaFunctionsList()
|
public static string GetLuaFunctionsList()
|
||||||
{
|
{
|
||||||
var list = new StringBuilder();
|
var list = new StringBuilder();
|
||||||
foreach (var function in GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList)
|
foreach (var function in GlobalWin.Tools.LuaConsole.LuaImp.Docs)
|
||||||
{
|
{
|
||||||
list.AppendLine(function.Name);
|
list.AppendLine(function.Name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
private readonly Sorting _columnSort = new Sorting();
|
private readonly Sorting _columnSort = new Sorting();
|
||||||
|
|
||||||
private List<LuaDocumentation.LibraryFunction> FunctionList = new List<LuaDocumentation.LibraryFunction>();
|
private List<LibraryFunction> FunctionList = new List<LibraryFunction>();
|
||||||
|
|
||||||
private List<LuaDocumentation.LibraryFunction> FilteredList
|
private List<LibraryFunction> FilteredList
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
@ -39,7 +39,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
private void LuaFunctionList_Load(object sender, EventArgs e)
|
private void LuaFunctionList_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
FunctionList = GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList.ToList();
|
FunctionList = GlobalWin.Tools.LuaConsole.LuaImp.Docs.ToList();
|
||||||
UpdateList();
|
UpdateList();
|
||||||
FilterBox.Focus();
|
FilterBox.Focus();
|
||||||
}
|
}
|
||||||
|
@ -183,7 +183,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
foreach (int index in indexes)
|
foreach (int index in indexes)
|
||||||
{
|
{
|
||||||
var libraryFunction = GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList[index];
|
var libraryFunction = GlobalWin.Tools.LuaConsole.LuaImp.Docs[index];
|
||||||
sb.Append(libraryFunction.Library).Append('.').Append(libraryFunction.Name).Append("()\n");
|
sb.Append(libraryFunction.Library).Append('.').Append(libraryFunction.Name).Append("()\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue