Lua - backend for more thorough self documenting, lua function list dialog has the same functionality as before but is primed for a better UI

This commit is contained in:
andres.delikat 2012-07-11 15:03:51 +00:00
parent 9da0cd3553
commit 3a73f8a427
4 changed files with 69 additions and 19 deletions

View File

@ -335,6 +335,7 @@
<Compile Include="tools\LuaButton.cs"> <Compile Include="tools\LuaButton.cs">
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>
<Compile Include="tools\LuaDocumentation.cs" />
<Compile Include="tools\LuaTextBox.cs"> <Compile Include="tools\LuaTextBox.cs">
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>

View File

@ -15,9 +15,9 @@ namespace BizHawk.MultiClient
{ {
public class LuaImplementation public class LuaImplementation
{ {
public LuaDocumentation docs = new LuaDocumentation();
Lua lua = new Lua(); Lua lua = new Lua();
LuaConsole Caller; LuaConsole Caller;
public List<string> LuaLibraryList = new List<string>();
public EventWaitHandle LuaWait; public EventWaitHandle LuaWait;
public bool isRunning; public bool isRunning;
private int CurrentMemoryDomain = 0; //Main memory by default private int CurrentMemoryDomain = 0; //Main memory by default
@ -61,7 +61,7 @@ namespace BizHawk.MultiClient
public LuaImplementation(LuaConsole passed) public LuaImplementation(LuaConsole passed)
{ {
LuaWait = new AutoResetEvent(false); LuaWait = new AutoResetEvent(false);
LuaLibraryList.Clear(); docs.Clear();
Caller = passed.get(); Caller = passed.get();
LuaRegister(lua); LuaRegister(lua);
} }
@ -80,80 +80,80 @@ namespace BizHawk.MultiClient
for (int i = 0; i < ConsoleFunctions.Length; i++) for (int i = 0; i < ConsoleFunctions.Length; i++)
{ {
lua.RegisterFunction("console." + ConsoleFunctions[i], this, this.GetType().GetMethod("console_" + ConsoleFunctions[i])); lua.RegisterFunction("console." + ConsoleFunctions[i], this, this.GetType().GetMethod("console_" + ConsoleFunctions[i]));
LuaLibraryList.Add("console." + ConsoleFunctions[i]); docs.Add("console", "console." + ConsoleFunctions[i], this.GetType().GetMethod("console_" + ConsoleFunctions[i]));
} }
lua.NewTable("gui"); lua.NewTable("gui");
for (int i = 0; i < GuiFunctions.Length; i++) for (int i = 0; i < GuiFunctions.Length; i++)
{ {
lua.RegisterFunction("gui." + GuiFunctions[i], this, this.GetType().GetMethod("gui_" + GuiFunctions[i])); lua.RegisterFunction("gui." + GuiFunctions[i], this, this.GetType().GetMethod("gui_" + GuiFunctions[i]));
LuaLibraryList.Add("gui." + GuiFunctions[i]); docs.Add("gui", "gui." + GuiFunctions[i], this.GetType().GetMethod("gui_" + GuiFunctions[i]));
} }
lua.NewTable("emu"); lua.NewTable("emu");
for (int i = 0; i < EmuFunctions.Length; i++) for (int i = 0; i < EmuFunctions.Length; i++)
{ {
lua.RegisterFunction("emu." + EmuFunctions[i], this, this.GetType().GetMethod("emu_" + EmuFunctions[i])); lua.RegisterFunction("emu." + EmuFunctions[i], this, this.GetType().GetMethod("emu_" + EmuFunctions[i]));
LuaLibraryList.Add("emu." + EmuFunctions[i]); docs.Add("emu", "emu." + EmuFunctions[i], this.GetType().GetMethod("emu_" + EmuFunctions[i]));
} }
lua.NewTable("memory"); lua.NewTable("memory");
for (int i = 0; i < MemoryFunctions.Length; i++) for (int i = 0; i < MemoryFunctions.Length; i++)
{ {
lua.RegisterFunction("memory." + MemoryFunctions[i], this, this.GetType().GetMethod("memory_" + MemoryFunctions[i])); lua.RegisterFunction("memory." + MemoryFunctions[i], this, this.GetType().GetMethod("memory_" + MemoryFunctions[i]));
LuaLibraryList.Add("memory." + MemoryFunctions[i]); docs.Add("memory", "memory." + MemoryFunctions[i], this.GetType().GetMethod("memory_" + MemoryFunctions[i]));
} }
lua.NewTable("mainmemory"); lua.NewTable("mainmemory");
for (int i = 0; i < MainMemoryFunctions.Length; i++) for (int i = 0; i < MainMemoryFunctions.Length; i++)
{ {
lua.RegisterFunction("mainmemory." + MainMemoryFunctions[i], this, this.GetType().GetMethod("mainmemory_" + MainMemoryFunctions[i])); lua.RegisterFunction("mainmemory." + MainMemoryFunctions[i], this, this.GetType().GetMethod("mainmemory_" + MainMemoryFunctions[i]));
LuaLibraryList.Add("mainmemory." + MainMemoryFunctions[i]); docs.Add("mainmemory", "mainmemory." + MainMemoryFunctions[i], this.GetType().GetMethod("mainmemory_" + MainMemoryFunctions[i]));
} }
lua.NewTable("savestate"); lua.NewTable("savestate");
for (int i = 0; i < SaveStateFunctions.Length; i++) for (int i = 0; i < SaveStateFunctions.Length; i++)
{ {
lua.RegisterFunction("savestate." + SaveStateFunctions[i], this, this.GetType().GetMethod("savestate_" + SaveStateFunctions[i])); lua.RegisterFunction("savestate." + SaveStateFunctions[i], this, this.GetType().GetMethod("savestate_" + SaveStateFunctions[i]));
LuaLibraryList.Add("savestate." + SaveStateFunctions[i]); docs.Add("savestate", "savestate." + SaveStateFunctions[i], this.GetType().GetMethod("savestate_" + SaveStateFunctions[i]));
} }
lua.NewTable("movie"); lua.NewTable("movie");
for (int i = 0; i < MovieFunctions.Length; i++) for (int i = 0; i < MovieFunctions.Length; i++)
{ {
lua.RegisterFunction("movie." + MovieFunctions[i], this, this.GetType().GetMethod("movie_" + MovieFunctions[i])); lua.RegisterFunction("movie." + MovieFunctions[i], this, this.GetType().GetMethod("movie_" + MovieFunctions[i]));
LuaLibraryList.Add("movie." + MovieFunctions[i]); docs.Add("movie", "movie." + MovieFunctions[i], this.GetType().GetMethod("movie_" + MovieFunctions[i]));
} }
lua.NewTable("input"); lua.NewTable("input");
for (int i = 0; i < InputFunctions.Length; i++) for (int i = 0; i < InputFunctions.Length; i++)
{ {
lua.RegisterFunction("input." + InputFunctions[i], this, this.GetType().GetMethod("input_" + InputFunctions[i])); lua.RegisterFunction("input." + InputFunctions[i], this, this.GetType().GetMethod("input_" + InputFunctions[i]));
LuaLibraryList.Add("input." + InputFunctions[i]); docs.Add("input", "input." + InputFunctions[i], this.GetType().GetMethod("input_" + InputFunctions[i]));
} }
lua.NewTable("joypad"); lua.NewTable("joypad");
for (int i = 0; i < JoypadFunctions.Length; i++) for (int i = 0; i < JoypadFunctions.Length; i++)
{ {
lua.RegisterFunction("joypad." + JoypadFunctions[i], this, this.GetType().GetMethod("joypad_" + JoypadFunctions[i])); lua.RegisterFunction("joypad." + JoypadFunctions[i], this, this.GetType().GetMethod("joypad_" + JoypadFunctions[i]));
LuaLibraryList.Add("joypad." + JoypadFunctions[i]); docs.Add("joypad", "joypad." + JoypadFunctions[i], this.GetType().GetMethod("joypad_" + JoypadFunctions[i]));
} }
lua.NewTable("client"); lua.NewTable("client");
for (int i = 0; i < MultiClientFunctions.Length; i++) for (int i = 0; i < MultiClientFunctions.Length; i++)
{ {
lua.RegisterFunction("client." + MultiClientFunctions[i], this, this.GetType().GetMethod("client_" + MultiClientFunctions[i])); lua.RegisterFunction("client." + MultiClientFunctions[i], this, this.GetType().GetMethod("client_" + MultiClientFunctions[i]));
LuaLibraryList.Add("client." + MultiClientFunctions[i]); docs.Add("client", "client." + MultiClientFunctions[i], this.GetType().GetMethod("client_" + MultiClientFunctions[i]));
} }
lua.NewTable("forms"); lua.NewTable("forms");
for (int i = 0; i < FormsFunctions.Length; i++) for (int i = 0; i < FormsFunctions.Length; i++)
{ {
lua.RegisterFunction("forms." + FormsFunctions[i], this, this.GetType().GetMethod("forms_" + FormsFunctions[i])); lua.RegisterFunction("forms." + FormsFunctions[i], this, this.GetType().GetMethod("forms_" + FormsFunctions[i]));
LuaLibraryList.Add("forms." + FormsFunctions[i]); docs.Add("forms", "forms." + FormsFunctions[i], this.GetType().GetMethod("forms_" + FormsFunctions[i]));
} }
LuaLibraryList.Sort(); docs.Sort();
} }
public Lua SpawnCoroutine(string File) public Lua SpawnCoroutine(string File)
@ -455,11 +455,11 @@ namespace BizHawk.MultiClient
public string console_getluafunctionslist() public string console_getluafunctionslist()
{ {
string list = ""; string list = "";
foreach (string l in LuaLibraryList) foreach (LuaDocumentation.LibraryFunction l in Global.MainForm.LuaConsole1.LuaImp.docs.FunctionList)
{ {
list += l + "\n"; list += l.name + "\n";
} }
return list; return list;
} }

View File

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BizHawk.MultiClient.tools
{
public class LuaDocumentation
{
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()
{
FunctionList = FunctionList.OrderBy(x => x.name).ToList();
}
public class LibraryFunction
{
public LibraryFunction(string method_lib, string method_name, System.Reflection.MethodInfo method)
{
library = method_lib;
name = method_name;
System.Reflection.ParameterInfo[] info = method.GetParameters();
foreach (System.Reflection.ParameterInfo p in info)
{
parameters.Add(p.ToString());
}
return_type = method.ReturnType.ToString();
}
public string library = "";
public string name = "";
public List<string> parameters = new List<string>();
public string return_type = "";
}
}
}

View File

@ -6,6 +6,7 @@ using System.Drawing;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.MultiClient.tools;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
@ -20,9 +21,9 @@ namespace BizHawk.MultiClient
{ {
FunctionBox.Text = ""; FunctionBox.Text = "";
foreach (string l in Global.MainForm.LuaConsole1.LuaImp.LuaLibraryList) foreach (LuaDocumentation.LibraryFunction l in Global.MainForm.LuaConsole1.LuaImp.docs.FunctionList)
{ {
FunctionBox.Text += l + "\n"; FunctionBox.Text += l.name + "\n";
} }
} }