Refactor the LuaDocumentation class to remove a bunch of unnecessary stuff

This commit is contained in:
adelikat 2014-06-03 00:34:41 +00:00
parent bb1b1ff5b5
commit ba4e7d620b
4 changed files with 80 additions and 116 deletions

View File

@ -5,45 +5,10 @@ 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() { }
FunctionList = new List<LibraryFunction>();
}
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 public class LibraryFunction
@ -62,7 +27,7 @@ namespace BizHawk.Client.Common
Parameters.Add(p.ToString()); Parameters.Add(p.ToString());
} }
this._returnType = method.ReturnType.ToString(); _returnType = method.ReturnType.ToString();
Description = description; Description = description;
} }
@ -133,5 +98,4 @@ namespace BizHawk.Client.Common
} }
} }
} }
}
} }

View File

@ -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));
} }
} }
} }

View File

@ -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);
} }

View File

@ -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");
} }