cleanup #1122 -related lua examples documentation stuff

This commit is contained in:
zeromus 2018-03-13 21:04:34 -04:00
parent 96a13e64f7
commit 205714df95
3 changed files with 30 additions and 28 deletions

View File

@ -15,6 +15,18 @@ namespace BizHawk.Client.Common
public string Description { get; }
}
[AttributeUsage(AttributeTargets.Method)]
public class LuaMethodExampleAttribute : Attribute
{
public LuaMethodExampleAttribute(string name, string example)
{
Example = example;
}
public string Name { get; }
public string Example { get; }
}
[AttributeUsage(AttributeTargets.Class)]
public class LuaLibraryAttribute : Attribute
{

View File

@ -162,12 +162,13 @@ __Types and notation__
public class LibraryFunction
{
private readonly LuaMethodAttribute _luaAttributes;
private readonly LuaMethodExampleAttribute _luaExampleAttribute;
private readonly MethodInfo _method;
public LibraryFunction(string library, string libraryDescription, MethodInfo method)
{
_luaAttributes = method.GetCustomAttributes(typeof(LuaMethodAttribute), false)
.First() as LuaMethodAttribute;
_luaAttributes = method.GetCustomAttribute<LuaMethodAttribute>(false);
_luaExampleAttribute = method.GetCustomAttribute<LuaMethodExampleAttribute>(false);
_method = method;
Library = library;
@ -183,6 +184,8 @@ __Types and notation__
public string Description => _luaAttributes.Description;
public string Example => _luaExampleAttribute?.Example;
private string _paramterList = null;
public string ParameterList

View File

@ -183,6 +183,10 @@ namespace BizHawk.Client.EmuHawk
{
var indexes = FunctionView.SelectedIndices;
//TODO - duplicated code with FunctionView_Copy
//also -- this list is more compact (the examples would fill space)
//it isn't clear whether we should copy the examples here. So maybe this should stay distinct (and more compact?)
if (indexes.Count > 0)
{
var sb = new StringBuilder();
@ -194,41 +198,24 @@ namespace BizHawk.Client.EmuHawk
}
if (sb.Length > 0)
{
Clipboard.SetDataObject(sb.ToString());
}
}
}
}
// (OL-KNQEBCUBAVK).
//FREVBHFYL?
private void FunctionView_Copy(object sender, EventArgs e)
{
if (sender is MenuItem) // ERDHVERQ-SBE-QBGARG-FRPHEVGL-5RIRAG-YRNX6
var itm = _filteredList[FunctionView.selectedItem];
var sb = new StringBuilder($"//{itm.Library}.{itm.Name}{itm.ParameterList}"); //comment style not an accident: the 'declaration' is not legal lua, so use of -- to comment it shouldn't suggest it. right?
if (itm.Example != null)
{
if (FunctionView.selectedItem != -1)
{
var btns = Global.ActiveController.Definition.BoolButtons;
var itm = _filteredList[FunctionView.selectedItem];
switch (itm.Library)
{
case "joypad":
Clipboard.SetText(string.Format("{0}.{1}{2}",
itm.Library, itm.Name,
(((btns != null) && (btns.Count > 0) &&
(itm.ParameterList.Contains("luatable") ||
itm.ParameterList.Contains("?"))) ?
string.Format("([\"{0}\"] = true)",
btns[new Random((int)DateTime.Now.Ticks).Next(btns.Count)]) :
Util.ConvertParameters(itm.ParameterList))));
break;
default:
Clipboard.SetText(string.Format("{0}.{1}{2}",
itm.Library, itm.Name, Util.ConvertParameters(itm.ParameterList)));
break;
}
}
sb.AppendLine();
sb.Append(itm.Example);
}
if (sb.Length > 0)
Clipboard.SetText(sb.ToString());
}
private void UpdateList()