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
|
||||
{
|
||||
public interface ILuaDocumentation
|
||||
{
|
||||
void Add(string methodLib, string methodName, MethodInfo method, string description);
|
||||
}
|
||||
|
||||
public class LuaDocumentation : ILuaDocumentation
|
||||
public class LuaDocumentation : List<LibraryFunction>
|
||||
{
|
||||
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; }
|
||||
|
||||
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)
|
||||
Parameters = new List<string>();
|
||||
foreach (var p in info)
|
||||
{
|
||||
Library = methodLib;
|
||||
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;
|
||||
Parameters.Add(p.ToString());
|
||||
}
|
||||
|
||||
public string Library { get; set; }
|
||||
public string Name { get; set; }
|
||||
public List<string> Parameters { get; set; }
|
||||
_returnType = method.ReturnType.ToString();
|
||||
|
||||
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();
|
||||
list.Append('(');
|
||||
for (var i = 0; i < Parameters.Count; i++)
|
||||
var param =
|
||||
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)
|
||||
{
|
||||
var param =
|
||||
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(", ");
|
||||
}
|
||||
|
||||
list.Append(')');
|
||||
|
||||
return list.ToString();
|
||||
}
|
||||
|
||||
list.Append(')');
|
||||
|
||||
return list.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public string ReturnType
|
||||
public string ReturnType
|
||||
{
|
||||
get
|
||||
{
|
||||
get
|
||||
{
|
||||
return _returnType
|
||||
.Replace("System.", string.Empty)
|
||||
.Replace("LuaInterface.", string.Empty)
|
||||
.ToLower()
|
||||
.Trim();
|
||||
}
|
||||
return _returnType
|
||||
.Replace("System.", string.Empty)
|
||||
.Replace("LuaInterface.", string.Empty)
|
||||
.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);
|
||||
|
||||
|
@ -48,7 +48,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
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()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -13,9 +13,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
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
|
||||
{
|
||||
|
@ -39,7 +39,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void LuaFunctionList_Load(object sender, EventArgs e)
|
||||
{
|
||||
FunctionList = GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList.ToList();
|
||||
FunctionList = GlobalWin.Tools.LuaConsole.LuaImp.Docs.ToList();
|
||||
UpdateList();
|
||||
FilterBox.Focus();
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
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");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue