Lua - add some more documentation, add a method that generates tasvideos wiki markup of the documentation and outputs to a file (method not wired to anything, there to save me tons of time when releasing)

This commit is contained in:
adelikat 2014-06-03 02:19:13 +00:00
parent d037c6ed60
commit 0649d1c77e
14 changed files with 88 additions and 5 deletions

View File

@ -1,8 +1,11 @@
using System;
using System.ComponentModel;
using LuaInterface;
namespace BizHawk.Client.Common
{
[Description("A library for performing standard bitwise operations.")]
public sealed class BitLuaLibrary : LuaLibraryBase
{
public BitLuaLibrary(Lua lua)

View File

@ -1,10 +1,13 @@
using System;
using System.Linq;
using System.ComponentModel;
using LuaInterface;
namespace BizHawk.Client.Common
{
[Description("A library for registering lua functions to emulator events.\n All events support multiple registered methods.\nAll registered event methods can be named and return a Guid when registered")]
public sealed class EventLuaLibrary : LuaLibraryBase
{
private readonly LuaFunctionList _luaFunctions = new LuaFunctionList();

View File

@ -1,9 +1,12 @@
using System;
using System.ComponentModel;
using LuaInterface;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common
{
[Description("Main memory library reads and writes from the Main memory domain (the default memory domain set by any given core)")]
public sealed class MainMemoryLuaLibrary : LuaMemoryBase
{
public MainMemoryLuaLibrary(Lua lua)

View File

@ -1,9 +1,12 @@
using System;
using System.ComponentModel;
using LuaInterface;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common
{
[Description("These functions behavior identically to the mainmemory functions but the user can set the memory domain to read and write from. The default domain is main memory. Use getcurrentmemorydomain(), and setcurrentmemorydomain() to control which domain is used. Each core has its own set of valid memory domains. Use getmemorydomainlist() to get a list of memory domains for the current core loaded.")]
public sealed class MemoryLuaLibrary : LuaMemoryBase
{
private int _currentMemoryDomain; // Main memory by default probably (index 0 is currently always main memory but may never be)

View File

@ -1,13 +1,15 @@
using System;
using System.ComponentModel;
using System.Linq;
using LuaInterface;
using BizHawk.Emulation.Cores.Nintendo.NES;
using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES;
namespace BizHawk.Client.Common
{
[Description("Functions related specifically to Nes Cores")]
public sealed class NesLuaLibrary : LuaLibraryBase
{
// TODO:

View File

@ -1,9 +1,12 @@
using System;
using System.ComponentModel;
using LuaInterface;
using BizHawk.Emulation.Cores.Nintendo.SNES;
namespace BizHawk.Client.Common
{
[Description("Functions specific to SNESHawk (functions may not run when an SNES game is not loaded)")]
public sealed class SnesLuaLibrary : LuaLibraryBase
{
public SnesLuaLibrary(Lua lua)

View File

@ -1,10 +1,12 @@
using System;
using System.ComponentModel;
using System.Linq;
using LuaInterface;
namespace BizHawk.Client.Common
{
[Description("A library exposing standard .NET string methods")]
public sealed class StringLuaLibrary : LuaLibraryBase
{
public override string Name { get { return "bizstring"; } }

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
@ -9,6 +10,46 @@ namespace BizHawk.Client.Common
{
public LuaDocumentation()
:base() { }
public void ToTASVideosWikiMarkup()
{
var sb = new StringBuilder();
sb
.AppendLine("[module:ListParents]")
.AppendLine()
.AppendLine("This page documents the the behavior and parameters of Lua functions available for the [BizHawk] emulator.")
.AppendLine()
.AppendLine();
foreach (var library in this.Select(x => new { Name = x.Library, Description = x.LibraryDescription }).Distinct())
{
sb
.AppendFormat("%%TAB {0}%%", library.Name)
.AppendLine()
.AppendLine();
if (!string.IsNullOrWhiteSpace(library.Description))
{
sb
.Append(library.Description)
.AppendLine()
.AppendLine();
}
foreach (var func in this.Where(x => x.Library == library.Name))
{
sb
.AppendFormat("__{0}.{1}__%%%", func.Library, func.Name)
.AppendLine().AppendLine()
.AppendFormat("* {0} {1}.{2}{3}", func.ReturnType, func.Library, func.Name, func.ParameterList)
.AppendLine().AppendLine()
.AppendFormat("* {0}", func.Description)
.AppendLine().AppendLine();
}
}
File.WriteAllText(Path.Combine(PathManager.GetExeDirectoryAbsolute(), "LuaDocumentationWiki.txt"), sb.ToString());
}
}
public class LibraryFunction
@ -37,6 +78,7 @@ namespace BizHawk.Client.Common
public List<string> Parameters { get; set; }
public string Description { get; set; }
public string LibraryDescription { get; set; }
public string ParameterList
{

View File

@ -2,6 +2,7 @@
using System.Linq;
using LuaInterface;
using BizHawk.Common.ReflectionExtensions;
namespace BizHawk.Client.Common
{
@ -30,7 +31,7 @@ namespace BizHawk.Client.Common
}
}
public virtual void LuaRegister(LuaDocumentation docs = null)
public virtual void LuaRegister(Type callingLibrary, LuaDocumentation docs = null)
{
Lua.NewTable(Name);
@ -48,7 +49,10 @@ namespace BizHawk.Client.Common
if (docs != null)
{
docs.Add(new LibraryFunction(Name, luaMethodAttr.Name, method, luaMethodAttr.Description));
docs.Add(new LibraryFunction(Name, luaMethodAttr.Name, method, luaMethodAttr.Description)
{
LibraryDescription = callingLibrary.Description()
});
}
}
}

View File

@ -1,11 +1,13 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using LuaInterface;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
[Description("A library for manipulating the EmuHawk client UI")]
public sealed class EmuHawkLuaLibrary : LuaLibraryBase
{
private readonly Dictionary<int, string> _filterMappings = new Dictionary<int, string>

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
@ -9,6 +10,7 @@ using LuaInterface;
namespace BizHawk.Client.EmuHawk
{
[Description("A library for creating and managing custom dialogs")]
public sealed class FormsLuaLibrary : LuaLibraryBase
{
public FormsLuaLibrary(Lua lua)

View File

@ -19,7 +19,7 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"get",
"Returns a lua table of all the buttons the user is currently pressing on their keyboard and gamepads"
"Returns a lua table of all the buttons the user is currently pressing on their keyboard and gamepads\nAll buttons that are pressed have their key values set to true; all others remain null.\nAll key names use the names from http://slimdx.mdxinfo.com/latestdocs/Help/Html/T_SlimDX_DirectInput_Key.htm and are case-sensitive."
)]
public LuaTable Get()
{

View File

@ -68,7 +68,7 @@ namespace BizHawk.Client.EmuHawk
foreach (var lib in libs)
{
var instance = (LuaLibraryBase)Activator.CreateInstance(lib, _lua);
instance.LuaRegister(Docs);
instance.LuaRegister(lib, Docs);
Libraries.Add(lib, instance);
}

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
@ -11,6 +12,19 @@ namespace BizHawk.Common.ReflectionExtensions
/// </summary>
public static class ReflectionUtil
{
public static string Description(this Type type)
{
var descriptions = (DescriptionAttribute[])
type.GetCustomAttributes(typeof(DescriptionAttribute), false);
if (descriptions.Length == 0)
{
return string.Empty;
}
return descriptions[0].Description;
}
/// <summary>
/// Takes an object and determines if it has methodName as a public method
/// </summary>