lua related code cleanup

This commit is contained in:
adelikat 2013-10-28 20:57:25 +00:00
parent 8b30b4290a
commit b2c2de2064
20 changed files with 69 additions and 146 deletions

View File

@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BizHawk.Client.Common
{

View File

@ -1,16 +1,13 @@
using System;
using System.Linq;
using System.Text;
using LuaInterface;
namespace BizHawk.Client.Common
{
public class NamedLuaFunction
{
private LuaFunction _function;
private string _name;
private string _event;
private readonly LuaFunction _function;
private readonly string _name;
private readonly string _event;
public NamedLuaFunction(LuaFunction function, string theevent, string name = null)
{

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BizHawk.MultiClient
namespace BizHawk.MultiClient
{
public partial class EmuLuaLibrary
{

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizHawk.Client.Common;
namespace BizHawk.MultiClient

View File

@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LuaInterface;
using BizHawk.Client.Common;
namespace BizHawk.MultiClient
{
@ -18,7 +16,7 @@ namespace BizHawk.MultiClient
public string console_getluafunctionslist()
{
string list = "";
foreach (LuaDocumentation.LibraryFunction l in GlobalWinF.MainForm.LuaConsole1.LuaImp.docs.FunctionList)
foreach (LuaDocumentation.LibraryFunction l in GlobalWinF.MainForm.LuaConsole1.LuaImp.Docs.FunctionList)
{
list += l.name + "\n";
}
@ -44,10 +42,8 @@ namespace BizHawk.MultiClient
StringBuilder sb = new StringBuilder();
var lti = (lua_input as LuaTable);
List<string> Keys = new List<string>();
List<string> Values = new List<string>();
foreach (var key in lti.Keys) { Keys.Add(key.ToString()); }
foreach (var value in lti.Values) { Values.Add(value.ToString()); }
List<string> Keys = (from object key in lti.Keys select key.ToString()).ToList();
List<string> Values = (from object value in lti.Values select value.ToString()).ToList();
List<KeyValuePair<string, string>> KVPs = new List<KeyValuePair<string, string>>();
for (int i = 0; i < Keys.Count; i++)

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LuaInterface;
using BizHawk.Client.Common;
using BizHawk.Emulation.Consoles.Nintendo;
@ -166,8 +162,8 @@ namespace BizHawk.MultiClient
{
if (luaf != null)
{
Global.Emulator.CoreComm.InputCallback = delegate()
{
Global.Emulator.CoreComm.InputCallback = delegate
{
try
{
luaf.Call();

View File

@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LuaInterface;
using BizHawk.Client.Common;
@ -12,7 +10,7 @@ namespace BizHawk.MultiClient
{
#region Events Library Helpers
private LuaFunctionList lua_functions = new LuaFunctionList();
private readonly LuaFunctionList lua_functions = new LuaFunctionList();
public LuaFunctionList RegisteredFunctions { get { return lua_functions; } }
@ -104,14 +102,14 @@ namespace BizHawk.MultiClient
public string event_onframeend(LuaFunction luaf, string name = null)
{
NamedLuaFunction nlf = new NamedLuaFunction(luaf, "OnFrameEnd", name != null ? name.ToString() : null);
NamedLuaFunction nlf = new NamedLuaFunction(luaf, "OnFrameEnd", name);
lua_functions.Add(nlf);
return nlf.GUID.ToString();
}
public string event_onframestart(LuaFunction luaf, object name = null)
public string event_onframestart(LuaFunction luaf, string name = null)
{
NamedLuaFunction nlf = new NamedLuaFunction(luaf, "OnFrameStart", name != null ? name.ToString() : null);
NamedLuaFunction nlf = new NamedLuaFunction(luaf, "OnFrameStart", name);
lua_functions.Add(nlf);
return nlf.GUID.ToString();
}

View File

@ -2,11 +2,9 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LuaInterface;
using BizHawk.Client.Common;
namespace BizHawk.MultiClient
{
@ -14,7 +12,7 @@ namespace BizHawk.MultiClient
{
#region Forms Library Helpers
private List<LuaWinform> LuaForms = new List<LuaWinform>();
private readonly List<LuaWinform> LuaForms = new List<LuaWinform>();
public void WindowClosed(IntPtr handle)
{

View File

@ -2,9 +2,6 @@
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using LuaInterface;
using BizHawk.Client.Common;

View File

@ -1,12 +1,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing;
using System.Windows.Forms;
using System.Linq;
using System.Text;
using LuaInterface;
using BizHawk.Client.Common;
namespace BizHawk.MultiClient
{

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LuaInterface;
using BizHawk.Client.Common;

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LuaInterface;
using BizHawk.Client.Common;

View File

@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LuaInterface;
using BizHawk.Client.Common;
namespace BizHawk.MultiClient
@ -62,12 +58,12 @@ namespace BizHawk.MultiClient
private uint M_R_U8(int addr)
{
return Global.Emulator.MemoryDomains[CurrentMemoryDomain].PeekByte(addr);
return Global.Emulator.MemoryDomains[_current_memory_domain].PeekByte(addr);
}
private void M_W_U8(int addr, uint v)
{
Global.Emulator.MemoryDomains[CurrentMemoryDomain].PokeByte(addr, (byte)v);
Global.Emulator.MemoryDomains[_current_memory_domain].PokeByte(addr, (byte)v);
}
#endregion
@ -79,12 +75,12 @@ namespace BizHawk.MultiClient
public string memory_getcurrentmemorydomain()
{
return Global.Emulator.MemoryDomains[CurrentMemoryDomain].Name;
return Global.Emulator.MemoryDomains[_current_memory_domain].Name;
}
public int memory_getcurrentmemorydomainsize()
{
return Global.Emulator.MemoryDomains[CurrentMemoryDomain].Size;
return Global.Emulator.MemoryDomains[_current_memory_domain].Size;
}
public uint memory_readbyte(object lua_addr)
@ -96,7 +92,7 @@ namespace BizHawk.MultiClient
public float memory_readfloat(object lua_addr, bool bigendian)
{
int addr = LuaInt(lua_addr);
uint val = Global.Emulator.MemoryDomains[CurrentMemoryDomain].PeekDWord(addr, bigendian ? Endian.Big : Endian.Little);
uint val = Global.Emulator.MemoryDomains[_current_memory_domain].PeekDWord(addr, bigendian ? Endian.Big : Endian.Little);
byte[] bytes = BitConverter.GetBytes(val);
float _float = BitConverter.ToSingle(bytes, 0);
@ -116,7 +112,7 @@ namespace BizHawk.MultiClient
float dv = (float)(double)lua_v;
byte[] bytes = BitConverter.GetBytes(dv);
uint v = BitConverter.ToUInt32(bytes, 0);
Global.Emulator.MemoryDomains[CurrentMemoryDomain].PokeDWord(addr, v, bigendian ? Endian.Big : Endian.Little);
Global.Emulator.MemoryDomains[_current_memory_domain].PokeDWord(addr, v, bigendian ? Endian.Big : Endian.Little);
}
public bool memory_usememorydomain(object lua_input)
@ -128,7 +124,7 @@ namespace BizHawk.MultiClient
{
if (Global.Emulator.MemoryDomains[x].Name == lua_input.ToString())
{
CurrentMemoryDomain = x;
_current_memory_domain = x;
return true;
}
}

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LuaInterface;
using LuaInterface;
using BizHawk.Client.Common;
namespace BizHawk.MultiClient

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LuaInterface;
using System.Linq;
using BizHawk.Client.Common;
using BizHawk.Emulation.Consoles.Nintendo;
@ -25,13 +20,14 @@ namespace BizHawk.MultiClient
Watch.WatchSize.Byte,
Watch.DisplayType.Hex,
code,
false);
false
);
Global.CheatList.Add(new Cheat(
watch,
gg.Value.Value,
gg.Compare,
enabled: true));
gg.Compare
));
}
ToolHelpers.UpdateCheatRelatedTools();

View File

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LuaInterface;
using BizHawk.Client.Common;
using BizHawk.Client.Common;
namespace BizHawk.MultiClient
{

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.IO;
using LuaInterface;
using BizHawk.Client.Common;

View File

@ -1,36 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Windows.Forms;
using System.Drawing;
using System.Threading;
using System.Globalization;
using System.Text;
using LuaInterface;
using BizHawk.Client.Common;
using BizHawk.Emulation.Consoles.Nintendo;
namespace BizHawk.MultiClient
{
public partial class EmuLuaLibrary
{
private Lua _lua = new Lua();
private readonly LuaConsole Caller;
private int CurrentMemoryDomain; //Main memory by default
private readonly LuaConsole _caller;
private int _current_memory_domain; //Main memory by default
private Lua currThread;
public LuaDocumentation docs = new LuaDocumentation();
public bool isRunning;
public LuaDocumentation Docs = new LuaDocumentation();
public bool IsRunning;
public EventWaitHandle LuaWait;
public bool FrameAdvanceRequested;
public EmuLuaLibrary(LuaConsole passed)
{
LuaWait = new AutoResetEvent(false);
docs.Clear();
Caller = passed.get();
Docs.Clear();
_caller = passed.get();
LuaRegister(_lua);
}
@ -329,28 +319,28 @@ namespace BizHawk.MultiClient
{
lua.RegisterFunction("console." + t, this,
GetType().GetMethod("console_" + t));
docs.Add("console", t, GetType().GetMethod("console_" + t));
Docs.Add("console", t, GetType().GetMethod("console_" + t));
}
lua.NewTable("gui");
foreach (string t in GuiFunctions)
{
lua.RegisterFunction("gui." + t, this, GetType().GetMethod("gui_" + t));
docs.Add("gui", t, GetType().GetMethod("gui_" + t));
Docs.Add("gui", t, GetType().GetMethod("gui_" + t));
}
lua.NewTable("emu");
foreach (string t in EmuFunctions)
{
lua.RegisterFunction("emu." + t, this, GetType().GetMethod("emu_" + t));
docs.Add("emu", t, GetType().GetMethod("emu_" + t));
Docs.Add("emu", t, GetType().GetMethod("emu_" + t));
}
lua.NewTable("memory");
foreach (string t in MemoryFunctions)
{
lua.RegisterFunction("memory." + t, this, GetType().GetMethod("memory_" + t));
docs.Add("memory", t, GetType().GetMethod("memory_" + t));
Docs.Add("memory", t, GetType().GetMethod("memory_" + t));
}
lua.NewTable("mainmemory");
@ -358,7 +348,7 @@ namespace BizHawk.MultiClient
{
lua.RegisterFunction("mainmemory." + t, this,
GetType().GetMethod("mainmemory_" + t));
docs.Add("mainmemory", t, GetType().GetMethod("mainmemory_" + t));
Docs.Add("mainmemory", t, GetType().GetMethod("mainmemory_" + t));
}
lua.NewTable("savestate");
@ -366,28 +356,28 @@ namespace BizHawk.MultiClient
{
lua.RegisterFunction("savestate." + t, this,
GetType().GetMethod("savestate_" + t));
docs.Add("savestate", t, GetType().GetMethod("savestate_" + t));
Docs.Add("savestate", t, GetType().GetMethod("savestate_" + t));
}
lua.NewTable("movie");
foreach (string t in MovieFunctions)
{
lua.RegisterFunction("movie." + t, this, GetType().GetMethod("movie_" + t));
docs.Add("movie", t, GetType().GetMethod("movie_" + t));
Docs.Add("movie", t, GetType().GetMethod("movie_" + t));
}
lua.NewTable("input");
foreach (string t in InputFunctions)
{
lua.RegisterFunction("input." + t, this, GetType().GetMethod("input_" + t));
docs.Add("input", t, GetType().GetMethod("input_" + t));
Docs.Add("input", t, GetType().GetMethod("input_" + t));
}
lua.NewTable("joypad");
foreach (string t in JoypadFunctions)
{
lua.RegisterFunction("joypad." + t, this, GetType().GetMethod("joypad_" + t));
docs.Add("joypad", t, GetType().GetMethod("joypad_" + t));
Docs.Add("joypad", t, GetType().GetMethod("joypad_" + t));
}
lua.NewTable("client");
@ -395,45 +385,45 @@ namespace BizHawk.MultiClient
{
lua.RegisterFunction("client." + t, this,
GetType().GetMethod("client_" + t));
docs.Add("client", t, GetType().GetMethod("client_" + t));
Docs.Add("client", t, GetType().GetMethod("client_" + t));
}
lua.NewTable("forms");
foreach (string t in FormsFunctions)
{
lua.RegisterFunction("forms." + t, this, GetType().GetMethod("forms_" + t));
docs.Add("forms", t, GetType().GetMethod("forms_" + t));
Docs.Add("forms", t, GetType().GetMethod("forms_" + t));
}
lua.NewTable("bit");
foreach (string t in BitwiseFunctions)
{
lua.RegisterFunction("bit." + t, this, GetType().GetMethod("bit_" + t));
docs.Add("bit", t, GetType().GetMethod("bit_" + t));
Docs.Add("bit", t, GetType().GetMethod("bit_" + t));
}
lua.NewTable("nes");
foreach (string t in NESFunctions)
{
lua.RegisterFunction("nes." + t, this, GetType().GetMethod("nes_" + t));
docs.Add("nes", t, GetType().GetMethod("nes_" + t));
Docs.Add("nes", t, GetType().GetMethod("nes_" + t));
}
lua.NewTable("snes");
foreach (string t in SNESFunctions)
{
lua.RegisterFunction("snes." + t, this, GetType().GetMethod("snes_" + t));
docs.Add("snes", t, GetType().GetMethod("snes_" + t));
Docs.Add("snes", t, GetType().GetMethod("snes_" + t));
}
lua.NewTable("event");
foreach (string t in EventFunctions)
{
lua.RegisterFunction("event." + t, this, GetType().GetMethod("event_" + t));
docs.Add("event", t, GetType().GetMethod("event_" + t));
Docs.Add("event", t, GetType().GetMethod("event_" + t));
}
docs.Sort();
Docs.Sort();
}
#endregion
@ -505,8 +495,8 @@ namespace BizHawk.MultiClient
public void print(string s)
{
Caller.AddText(s);
Caller.AddText("\n");
_caller.AddText(s);
_caller.AddText("\n");
}
#endregion

View File

@ -23,7 +23,7 @@ namespace BizHawk.MultiClient
private void PopulateListView()
{
FunctionView.Items.Clear();
foreach (LuaDocumentation.LibraryFunction l in GlobalWinF.MainForm.LuaConsole1.LuaImp.docs.FunctionList)
foreach (LuaDocumentation.LibraryFunction l in GlobalWinF.MainForm.LuaConsole1.LuaImp.Docs.FunctionList)
{
ListViewItem item = new ListViewItem {Text = l.ReturnType};
item.SubItems.Add(l.library + ".");
@ -41,16 +41,16 @@ namespace BizHawk.MultiClient
switch (column)
{
case 0: //Return
GlobalWinF.MainForm.LuaConsole1.LuaImp.docs.FunctionList = GlobalWinF.MainForm.LuaConsole1.LuaImp.docs.FunctionList.OrderByDescending(x => x.ReturnType).ToList();
GlobalWinF.MainForm.LuaConsole1.LuaImp.Docs.FunctionList = GlobalWinF.MainForm.LuaConsole1.LuaImp.Docs.FunctionList.OrderByDescending(x => x.ReturnType).ToList();
break;
case 1: //Library
GlobalWinF.MainForm.LuaConsole1.LuaImp.docs.FunctionList = GlobalWinF.MainForm.LuaConsole1.LuaImp.docs.FunctionList.OrderByDescending(x => x.library).ToList();
GlobalWinF.MainForm.LuaConsole1.LuaImp.Docs.FunctionList = GlobalWinF.MainForm.LuaConsole1.LuaImp.Docs.FunctionList.OrderByDescending(x => x.library).ToList();
break;
case 2: //Name
GlobalWinF.MainForm.LuaConsole1.LuaImp.docs.FunctionList = GlobalWinF.MainForm.LuaConsole1.LuaImp.docs.FunctionList.OrderByDescending(x => x.name).ToList();
GlobalWinF.MainForm.LuaConsole1.LuaImp.Docs.FunctionList = GlobalWinF.MainForm.LuaConsole1.LuaImp.Docs.FunctionList.OrderByDescending(x => x.name).ToList();
break;
case 3: //Parameters
GlobalWinF.MainForm.LuaConsole1.LuaImp.docs.FunctionList = GlobalWinF.MainForm.LuaConsole1.LuaImp.docs.FunctionList.OrderByDescending(x => x.ParameterList).ToList();
GlobalWinF.MainForm.LuaConsole1.LuaImp.Docs.FunctionList = GlobalWinF.MainForm.LuaConsole1.LuaImp.Docs.FunctionList.OrderByDescending(x => x.ParameterList).ToList();
break;
}
}
@ -59,16 +59,16 @@ namespace BizHawk.MultiClient
switch (column)
{
case 0: //Return
GlobalWinF.MainForm.LuaConsole1.LuaImp.docs.FunctionList = GlobalWinF.MainForm.LuaConsole1.LuaImp.docs.FunctionList.OrderBy(x => x.ReturnType).ToList();
GlobalWinF.MainForm.LuaConsole1.LuaImp.Docs.FunctionList = GlobalWinF.MainForm.LuaConsole1.LuaImp.Docs.FunctionList.OrderBy(x => x.ReturnType).ToList();
break;
case 1: //Library
GlobalWinF.MainForm.LuaConsole1.LuaImp.docs.FunctionList = GlobalWinF.MainForm.LuaConsole1.LuaImp.docs.FunctionList.OrderBy(x => x.library).ToList();
GlobalWinF.MainForm.LuaConsole1.LuaImp.Docs.FunctionList = GlobalWinF.MainForm.LuaConsole1.LuaImp.Docs.FunctionList.OrderBy(x => x.library).ToList();
break;
case 2: //Name
GlobalWinF.MainForm.LuaConsole1.LuaImp.docs.FunctionList = GlobalWinF.MainForm.LuaConsole1.LuaImp.docs.FunctionList.OrderBy(x => x.name).ToList();
GlobalWinF.MainForm.LuaConsole1.LuaImp.Docs.FunctionList = GlobalWinF.MainForm.LuaConsole1.LuaImp.Docs.FunctionList.OrderBy(x => x.name).ToList();
break;
case 3: //Parameters
GlobalWinF.MainForm.LuaConsole1.LuaImp.docs.FunctionList = GlobalWinF.MainForm.LuaConsole1.LuaImp.docs.FunctionList.OrderBy(x => x.ParameterList).ToList();
GlobalWinF.MainForm.LuaConsole1.LuaImp.Docs.FunctionList = GlobalWinF.MainForm.LuaConsole1.LuaImp.Docs.FunctionList.OrderBy(x => x.ParameterList).ToList();
break;
}
}
@ -132,7 +132,7 @@ namespace BizHawk.MultiClient
foreach (int index in indexes)
{
var library_function = GlobalWinF.MainForm.LuaConsole1.LuaImp.docs.FunctionList[index];
var library_function = GlobalWinF.MainForm.LuaConsole1.LuaImp.Docs.FunctionList[index];
sb.Append(library_function.library).Append('.').Append(library_function.name).Append("()\n");
}

View File

@ -434,7 +434,7 @@ namespace BizHawk.MultiClient
private void GenerateLibraryRegex()
{
StringBuilder list = new StringBuilder();
List<string> Libs = GlobalWinF.MainForm.LuaConsole1.LuaImp.docs.GetLibraryList();
List<string> Libs = GlobalWinF.MainForm.LuaConsole1.LuaImp.Docs.GetLibraryList();
for (int i = 0; i < Libs.Count; i++)
{
list.Append(Libs[i]);
@ -659,7 +659,7 @@ namespace BizHawk.MultiClient
string currentword = CurrentWord();
if (IsLibraryWord(currentword))
{
List<string> libfunctions = GlobalWinF.MainForm.LuaConsole1.LuaImp.docs.GetFunctionsByLibrary(currentword);
List<string> libfunctions = GlobalWinF.MainForm.LuaConsole1.LuaImp.Docs.GetFunctionsByLibrary(currentword);
// Position autocomplete box near the cursor's current position
int x = LuaText.GetPositionFromCharIndex(LuaText.SelectionStart).X + LuaText.Location.X + 5;
@ -783,7 +783,7 @@ namespace BizHawk.MultiClient
private bool IsLibraryWord(string word)
{
List<string> Libs = GlobalWinF.MainForm.LuaConsole1.LuaImp.docs.GetLibraryList();
List<string> Libs = GlobalWinF.MainForm.LuaConsole1.LuaImp.Docs.GetLibraryList();
if (Libs.Contains(word))
{
return true;