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;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
2012-07-23 01:02:04 +00:00
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
void Add(string method_lib, string method_name, System.Reflection.MethodInfo method);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class LuaDocumentation : ILuaDocumentation
|
2012-07-11 15:03:51 +00:00
|
|
|
|
{
|
|
|
|
|
public List<LibraryFunction> FunctionList = new List<LibraryFunction>();
|
|
|
|
|
|
|
|
|
|
public void Add(string method_lib, string method_name, System.Reflection.MethodInfo method)
|
|
|
|
|
{
|
|
|
|
|
LibraryFunction f = new LibraryFunction(method_lib, method_name, method);
|
|
|
|
|
FunctionList.Add(f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2012-07-23 01:02:04 +00:00
|
|
|
|
public List<string> GetLibraryList()
|
|
|
|
|
{
|
|
|
|
|
HashSet<string> libs = new HashSet<string>();
|
|
|
|
|
foreach (LibraryFunction function in FunctionList)
|
|
|
|
|
{
|
2013-10-31 00:31:25 +00:00
|
|
|
|
libs.Add(function.Library);
|
2012-07-23 01:02:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return libs.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-23 02:24:48 +00:00
|
|
|
|
public List<string> GetFunctionsByLibrary(string library)
|
|
|
|
|
{
|
2013-10-31 00:31:25 +00:00
|
|
|
|
return (from t in FunctionList where t.Library == library select t.Name).ToList();
|
2012-07-23 02:24:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-11 15:03:51 +00:00
|
|
|
|
public class LibraryFunction
|
|
|
|
|
{
|
|
|
|
|
public LibraryFunction(string method_lib, string method_name, System.Reflection.MethodInfo method)
|
|
|
|
|
{
|
2013-10-31 00:31:25 +00:00
|
|
|
|
Library = method_lib;
|
|
|
|
|
Name = method_name;
|
2012-07-11 15:03:51 +00:00
|
|
|
|
System.Reflection.ParameterInfo[] info = method.GetParameters();
|
|
|
|
|
foreach (System.Reflection.ParameterInfo p in info)
|
|
|
|
|
{
|
2013-10-31 00:31:25 +00:00
|
|
|
|
Parameters.Add(p.ToString());
|
2012-07-11 15:03:51 +00:00
|
|
|
|
}
|
|
|
|
|
return_type = method.ReturnType.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-31 00:31:25 +00:00
|
|
|
|
public string Library = String.Empty;
|
|
|
|
|
public string Name = String.Empty;
|
|
|
|
|
public List<string> Parameters = new List<string>();
|
|
|
|
|
public string return_type = String.Empty;
|
2012-07-12 00:57:09 +00:00
|
|
|
|
|
|
|
|
|
public string ParameterList
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
StringBuilder list = new StringBuilder();
|
|
|
|
|
list.Append('(');
|
2013-10-31 00:31:25 +00:00
|
|
|
|
for (int i = 0; i < Parameters.Count; i++)
|
2012-07-12 00:57:09 +00:00
|
|
|
|
{
|
2013-10-31 00:31:25 +00:00
|
|
|
|
string param = Parameters[i].Replace("System", "").Replace("Object", "").Replace(" ", "").Replace(".", "").Replace("LuaInterface", "");
|
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
|
|
|
|
{
|
|
|
|
|
list.Append(',');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
list.Append(')');
|
|
|
|
|
return list.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string ReturnType
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2013-04-14 23:56:45 +00:00
|
|
|
|
return return_type.Replace("System.", "").Replace("LuaInterface.", "").ToLower().Trim();
|
2012-07-12 00:57:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-11 15:03:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|