2013-10-31 00:31:25 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2012-07-11 15:03:51 +00:00
|
|
|
|
using System.Linq;
|
2014-01-25 20:27:51 +00:00
|
|
|
|
using System.Reflection;
|
2012-07-11 15:03:51 +00:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
2013-10-31 23:55:17 +00:00
|
|
|
|
namespace BizHawk.Client.Common
|
2012-07-11 15:03:51 +00:00
|
|
|
|
{
|
2013-10-31 00:31:25 +00:00
|
|
|
|
public interface ILuaDocumentation
|
|
|
|
|
{
|
2014-01-25 20:27:51 +00:00
|
|
|
|
void Add(string methodLib, string methodName, MethodInfo method, string description);
|
2013-10-31 00:31:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class LuaDocumentation : ILuaDocumentation
|
2012-07-11 15:03:51 +00:00
|
|
|
|
{
|
2014-01-25 20:27:51 +00:00
|
|
|
|
public List<LibraryFunction> FunctionList { get; set; }
|
2012-07-11 15:03:51 +00:00
|
|
|
|
|
2014-01-25 20:27:51 +00:00
|
|
|
|
public LuaDocumentation()
|
|
|
|
|
{
|
|
|
|
|
FunctionList = new List<LibraryFunction>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Add(string methodLib, string methodName, MethodInfo method, string description)
|
2012-07-11 15:03:51 +00:00
|
|
|
|
{
|
2014-01-25 20:04:26 +00:00
|
|
|
|
FunctionList.Add(
|
2014-01-25 20:27:51 +00:00
|
|
|
|
new LibraryFunction(methodLib, methodName, method, description)
|
2014-01-25 20:04:26 +00:00
|
|
|
|
);
|
2012-07-11 15:03:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Clear()
|
|
|
|
|
{
|
|
|
|
|
FunctionList = new List<LibraryFunction>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Sort()
|
|
|
|
|
{
|
2013-10-31 00:31:25 +00:00
|
|
|
|
FunctionList = FunctionList.OrderBy(x => x.Library).ThenBy(x => x.Name).ToList();
|
2012-07-11 15:03:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-25 20:04:26 +00:00
|
|
|
|
public IEnumerable<string> GetLibraryList()
|
2012-07-23 01:02:04 +00:00
|
|
|
|
{
|
2014-01-25 20:04:26 +00:00
|
|
|
|
return FunctionList.Select(x => x.Library);
|
2012-07-23 01:02:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-25 20:27:51 +00:00
|
|
|
|
public IEnumerable<string> GetFunctionsByLibrary(string library)
|
2012-07-23 02:24:48 +00:00
|
|
|
|
{
|
2014-01-25 20:27:51 +00:00
|
|
|
|
return FunctionList
|
|
|
|
|
.Where(func => func.Library == library)
|
|
|
|
|
.Select(func => func.Name);
|
2012-07-23 02:24:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-11 15:03:51 +00:00
|
|
|
|
public class LibraryFunction
|
|
|
|
|
{
|
2014-01-25 20:27:51 +00:00
|
|
|
|
public LibraryFunction(string methodLib, string methodName, MethodInfo method, string description)
|
2012-07-11 15:03:51 +00:00
|
|
|
|
{
|
2014-01-25 20:27:51 +00:00
|
|
|
|
Library = methodLib;
|
|
|
|
|
Name = methodName;
|
2013-12-30 01:58:44 +00:00
|
|
|
|
var info = method.GetParameters();
|
2014-01-25 20:27:51 +00:00
|
|
|
|
|
|
|
|
|
Parameters = new List<string>();
|
2013-12-30 01:58:44 +00:00
|
|
|
|
foreach (var p in info)
|
2012-07-11 15:03:51 +00:00
|
|
|
|
{
|
2013-10-31 00:31:25 +00:00
|
|
|
|
Parameters.Add(p.ToString());
|
2012-07-11 15:03:51 +00:00
|
|
|
|
}
|
2013-12-30 01:58:44 +00:00
|
|
|
|
|
2014-01-25 20:27:51 +00:00
|
|
|
|
this._returnType = method.ReturnType.ToString();
|
2014-01-25 20:04:26 +00:00
|
|
|
|
|
|
|
|
|
Description = description;
|
2012-07-11 15:03:51 +00:00
|
|
|
|
}
|
2014-01-25 20:27:51 +00:00
|
|
|
|
|
|
|
|
|
public string Library { get; set; }
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
public List<string> Parameters { get; set; }
|
|
|
|
|
private readonly string _returnType = String.Empty;
|
2012-07-12 00:57:09 +00:00
|
|
|
|
|
2014-01-25 20:04:26 +00:00
|
|
|
|
public string Description { get; set; }
|
|
|
|
|
|
2012-07-12 00:57:09 +00:00
|
|
|
|
public string ParameterList
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2013-12-30 01:58:44 +00:00
|
|
|
|
var list = new StringBuilder();
|
2012-07-12 00:57:09 +00:00
|
|
|
|
list.Append('(');
|
2014-01-25 20:27:51 +00:00
|
|
|
|
for (var i = 0; i < Parameters.Count; i++)
|
2012-07-12 00:57:09 +00:00
|
|
|
|
{
|
2014-01-26 20:05:45 +00:00
|
|
|
|
var param =
|
|
|
|
|
Parameters[i].Replace("System", String.Empty)
|
|
|
|
|
.Replace("Object", String.Empty)
|
|
|
|
|
.Replace(" ", String.Empty)
|
|
|
|
|
.Replace(".", String.Empty)
|
|
|
|
|
.Replace("LuaInterface", String.Empty)
|
|
|
|
|
.Replace("Boolean", "bool ")
|
|
|
|
|
.Replace("String", "string ")
|
|
|
|
|
.Replace("LuaTable", "table ")
|
|
|
|
|
.Replace("LuaFunction", "func ");
|
2014-01-25 20:27:51 +00:00
|
|
|
|
|
2012-07-12 00:57:09 +00:00
|
|
|
|
list.Append(param);
|
2013-10-31 00:31:25 +00:00
|
|
|
|
if (i < Parameters.Count - 1)
|
2012-07-12 00:57:09 +00:00
|
|
|
|
{
|
2014-01-26 20:05:45 +00:00
|
|
|
|
list.Append(", ");
|
2012-07-12 00:57:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-30 01:58:44 +00:00
|
|
|
|
|
2012-07-12 00:57:09 +00:00
|
|
|
|
list.Append(')');
|
2014-01-25 20:27:51 +00:00
|
|
|
|
|
2012-07-12 00:57:09 +00:00
|
|
|
|
return list.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string ReturnType
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2014-01-25 20:27:51 +00:00
|
|
|
|
return _returnType
|
|
|
|
|
.Replace("System.", String.Empty)
|
|
|
|
|
.Replace("LuaInterface.", String.Empty)
|
|
|
|
|
.ToLower()
|
|
|
|
|
.Trim();
|
2012-07-12 00:57:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-11 15:03:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|