Lua Console - lua functions list menu item. Lua - console.clear, console.getluafunctionslist, emu.getsystemid

This commit is contained in:
andres.delikat 2012-01-22 03:14:31 +00:00
parent 5f66de57ec
commit 48c651cfc7
3 changed files with 142 additions and 63 deletions

View File

@ -12,9 +12,11 @@ namespace BizHawk.MultiClient
{ {
Lua lua = new Lua(); Lua lua = new Lua();
LuaConsole Caller; LuaConsole Caller;
public String LuaLibraryList = "";
public LuaImplementation(LuaConsole passed) public LuaImplementation(LuaConsole passed)
{ {
LuaLibraryList = "";
Caller = passed.get(); Caller = passed.get();
lua.RegisterFunction("print", this, this.GetType().GetMethod("print")); lua.RegisterFunction("print", this, this.GetType().GetMethod("print"));
@ -23,36 +25,42 @@ 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 += "console." + ConsoleFunctions[i] + "\n";
} }
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 += "emu." + EmuFunctions[i] + "\n";
} }
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 += "memory." + MemoryFunctions[i] + "\n";
} }
lua.NewTable("savestate"); lua.NewTable("savestate");
for (int i = 0; i < SaveStateFunctions.Length; i++) for (int i = 0; i < SaveStateFunctions.Length; i++)
{ {
//lua.RegisterFunction("statestate." + SaveStateFunctions[i], this, this.GetType().GetMethod("savestate_" + SaveStateFunctions[i])); //lua.RegisterFunction("statestate." + SaveStateFunctions[i], this, this.GetType().GetMethod("savestate_" + SaveStateFunctions[i]));
//LuaLibraryList += "savestate." + SaveStateFunctions[i] + "\n";
} }
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 += "movie." + MovieFunctions[i] + "\n";
} }
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." + MemoryFunctions[i], this, this.GetType().GetMethod("joypad_" + JoypadFunctions[i])); lua.RegisterFunction("joypad." + JoypadFunctions[i], this, this.GetType().GetMethod("joypad_" + JoypadFunctions[i]));
LuaLibraryList += "joypad." + JoypadFunctions[i] + "\n";
} }
} }
@ -70,18 +78,21 @@ namespace BizHawk.MultiClient
/*************library definitions********************/ /*************library definitions********************/
/****************************************************/ /****************************************************/
public static string[] ConsoleFunctions = new string[] { public static string[] ConsoleFunctions = new string[] {
"output" "output",
"clear",
"getluafunctionslist"
}; };
public static string[] EmuFunctions = new string[] { public static string[] EmuFunctions = new string[] {
//"frameadvance", "frameadvance",
"pause", "pause",
"unpause", "unpause",
"togglepause", "togglepause",
//"speedmode", //"speedmode",
//"framecount", "framecount",
//"lagcount", "lagcount",
//"islagged", "islagged",
"getsystemid"
//"registerbefore", //"registerbefore",
//"registerafter", //"registerafter",
//"register" //"register"
@ -129,9 +140,25 @@ namespace BizHawk.MultiClient
Global.MainForm.LuaConsole1.WriteToOutputWindow(lua_input.ToString()); Global.MainForm.LuaConsole1.WriteToOutputWindow(lua_input.ToString());
} }
public void console_clear(object lua_input)
{
Global.MainForm.LuaConsole1.ClearOutputWindow();
}
public string console_getluafunctionslist()
{
return LuaLibraryList;
}
//---------------------------------------------------- //----------------------------------------------------
//Emu library //Emu library
//---------------------------------------------------- //----------------------------------------------------
public void emu_frameadvance()
{
//Global.MainForm.PressFrameAdvance = true;
//Global.Emulator.FrameAdvance(true);
}
public void emu_pause() public void emu_pause()
{ {
@ -148,6 +175,26 @@ namespace BizHawk.MultiClient
Global.MainForm.TogglePause(); Global.MainForm.TogglePause();
} }
public int emu_framecount()
{
return Global.Emulator.Frame;
}
public int emu_lagcount()
{
return Global.Emulator.LagCount;
}
public bool emu_islagged()
{
return Global.Emulator.IsLagFrame;
}
public string emu_getsystemid()
{
return Global.Emulator.SystemId;
}
//---------------------------------------------------- //----------------------------------------------------
//Memory library //Memory library
//---------------------------------------------------- //----------------------------------------------------

View File

@ -43,8 +43,14 @@
this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.newToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.newToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openSessionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveAsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveAsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator9 = new System.Windows.Forms.ToolStripSeparator();
this.recentSessionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.noneToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator8 = new System.Windows.Forms.ToolStripSeparator();
this.clearToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.recentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.recentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.noneToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.noneToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
@ -52,6 +58,7 @@
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.scriptToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.scriptToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toggleToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toggleToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.removeScriptToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.removeScriptToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
@ -79,13 +86,8 @@
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.toolStripButtonMoveUp = new System.Windows.Forms.ToolStripButton(); this.toolStripButtonMoveUp = new System.Windows.Forms.ToolStripButton();
this.toolStripButtonMoveDown = new System.Windows.Forms.ToolStripButton(); this.toolStripButtonMoveDown = new System.Windows.Forms.ToolStripButton();
this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.recentSessionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.luaFunctionsListToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.noneToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator8 = new System.Windows.Forms.ToolStripSeparator();
this.clearToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator9 = new System.Windows.Forms.ToolStripSeparator();
this.openSessionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.contextMenuStrip1.SuspendLayout(); this.contextMenuStrip1.SuspendLayout();
this.menuStrip1.SuspendLayout(); this.menuStrip1.SuspendLayout();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
@ -186,7 +188,8 @@
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem, this.fileToolStripMenuItem,
this.scriptToolStripMenuItem, this.scriptToolStripMenuItem,
this.optionsToolStripMenuItem}); this.optionsToolStripMenuItem,
this.helpToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(584, 24); this.menuStrip1.Size = new System.Drawing.Size(584, 24);
@ -218,6 +221,14 @@
this.newToolStripMenuItem.Text = "&New Session"; this.newToolStripMenuItem.Text = "&New Session";
this.newToolStripMenuItem.Click += new System.EventHandler(this.newToolStripMenuItem_Click); this.newToolStripMenuItem.Click += new System.EventHandler(this.newToolStripMenuItem_Click);
// //
// openSessionToolStripMenuItem
//
this.openSessionToolStripMenuItem.Image = global::BizHawk.MultiClient.Properties.Resources.OpenFile;
this.openSessionToolStripMenuItem.Name = "openSessionToolStripMenuItem";
this.openSessionToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O)));
this.openSessionToolStripMenuItem.Size = new System.Drawing.Size(243, 22);
this.openSessionToolStripMenuItem.Text = "&Open Session";
//
// saveToolStripMenuItem // saveToolStripMenuItem
// //
this.saveToolStripMenuItem.Image = global::BizHawk.MultiClient.Properties.Resources.SaveAs; this.saveToolStripMenuItem.Image = global::BizHawk.MultiClient.Properties.Resources.SaveAs;
@ -236,6 +247,38 @@
this.saveAsToolStripMenuItem.Text = "Save Session &As..."; this.saveAsToolStripMenuItem.Text = "Save Session &As...";
this.saveAsToolStripMenuItem.Click += new System.EventHandler(this.saveAsToolStripMenuItem_Click); this.saveAsToolStripMenuItem.Click += new System.EventHandler(this.saveAsToolStripMenuItem_Click);
// //
// toolStripSeparator9
//
this.toolStripSeparator9.Name = "toolStripSeparator9";
this.toolStripSeparator9.Size = new System.Drawing.Size(240, 6);
//
// recentSessionsToolStripMenuItem
//
this.recentSessionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.noneToolStripMenuItem1,
this.toolStripSeparator8,
this.clearToolStripMenuItem1});
this.recentSessionsToolStripMenuItem.Name = "recentSessionsToolStripMenuItem";
this.recentSessionsToolStripMenuItem.Size = new System.Drawing.Size(243, 22);
this.recentSessionsToolStripMenuItem.Text = "Recent Sessions";
//
// noneToolStripMenuItem1
//
this.noneToolStripMenuItem1.Name = "noneToolStripMenuItem1";
this.noneToolStripMenuItem1.Size = new System.Drawing.Size(110, 22);
this.noneToolStripMenuItem1.Text = "None";
//
// toolStripSeparator8
//
this.toolStripSeparator8.Name = "toolStripSeparator8";
this.toolStripSeparator8.Size = new System.Drawing.Size(107, 6);
//
// clearToolStripMenuItem1
//
this.clearToolStripMenuItem1.Name = "clearToolStripMenuItem1";
this.clearToolStripMenuItem1.Size = new System.Drawing.Size(110, 22);
this.clearToolStripMenuItem1.Text = "Clear";
//
// recentToolStripMenuItem // recentToolStripMenuItem
// //
this.recentToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.recentToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -251,18 +294,18 @@
// noneToolStripMenuItem // noneToolStripMenuItem
// //
this.noneToolStripMenuItem.Name = "noneToolStripMenuItem"; this.noneToolStripMenuItem.Name = "noneToolStripMenuItem";
this.noneToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.noneToolStripMenuItem.Size = new System.Drawing.Size(110, 22);
this.noneToolStripMenuItem.Text = "None"; this.noneToolStripMenuItem.Text = "None";
// //
// toolStripSeparator3 // toolStripSeparator3
// //
this.toolStripSeparator3.Name = "toolStripSeparator3"; this.toolStripSeparator3.Name = "toolStripSeparator3";
this.toolStripSeparator3.Size = new System.Drawing.Size(149, 6); this.toolStripSeparator3.Size = new System.Drawing.Size(107, 6);
// //
// clearToolStripMenuItem // clearToolStripMenuItem
// //
this.clearToolStripMenuItem.Name = "clearToolStripMenuItem"; this.clearToolStripMenuItem.Name = "clearToolStripMenuItem";
this.clearToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.clearToolStripMenuItem.Size = new System.Drawing.Size(110, 22);
this.clearToolStripMenuItem.Text = "Clear"; this.clearToolStripMenuItem.Text = "Clear";
// //
// toolStripSeparator1 // toolStripSeparator1
@ -296,6 +339,14 @@
this.scriptToolStripMenuItem.Size = new System.Drawing.Size(46, 20); this.scriptToolStripMenuItem.Size = new System.Drawing.Size(46, 20);
this.scriptToolStripMenuItem.Text = "&Script"; this.scriptToolStripMenuItem.Text = "&Script";
// //
// openToolStripMenuItem
//
this.openToolStripMenuItem.Image = global::BizHawk.MultiClient.Properties.Resources.OpenFile;
this.openToolStripMenuItem.Name = "openToolStripMenuItem";
this.openToolStripMenuItem.Size = new System.Drawing.Size(201, 22);
this.openToolStripMenuItem.Text = "&Open Script";
this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click_1);
//
// toggleToolStripMenuItem // toggleToolStripMenuItem
// //
this.toggleToolStripMenuItem.Image = global::BizHawk.MultiClient.Properties.Resources.Refresh1; this.toggleToolStripMenuItem.Image = global::BizHawk.MultiClient.Properties.Resources.Refresh1;
@ -533,53 +584,20 @@
this.toolStripButtonMoveDown.Text = "Move Down"; this.toolStripButtonMoveDown.Text = "Move Down";
this.toolStripButtonMoveDown.Click += new System.EventHandler(this.toolStripButtonMoveDown_Click); this.toolStripButtonMoveDown.Click += new System.EventHandler(this.toolStripButtonMoveDown_Click);
// //
// openToolStripMenuItem // helpToolStripMenuItem
// //
this.openToolStripMenuItem.Image = global::BizHawk.MultiClient.Properties.Resources.OpenFile; this.helpToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.openToolStripMenuItem.Name = "openToolStripMenuItem"; this.luaFunctionsListToolStripMenuItem});
this.openToolStripMenuItem.Size = new System.Drawing.Size(201, 22); this.helpToolStripMenuItem.Name = "helpToolStripMenuItem";
this.openToolStripMenuItem.Text = "&Open Script"; this.helpToolStripMenuItem.Size = new System.Drawing.Size(40, 20);
this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click_1); this.helpToolStripMenuItem.Text = "&Help";
// //
// recentSessionsToolStripMenuItem // luaFunctionsListToolStripMenuItem
// //
this.recentSessionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.luaFunctionsListToolStripMenuItem.Name = "luaFunctionsListToolStripMenuItem";
this.noneToolStripMenuItem1, this.luaFunctionsListToolStripMenuItem.Size = new System.Drawing.Size(170, 22);
this.toolStripSeparator8, this.luaFunctionsListToolStripMenuItem.Text = "&Lua Functions List";
this.clearToolStripMenuItem1}); this.luaFunctionsListToolStripMenuItem.Click += new System.EventHandler(this.luaFunctionsListToolStripMenuItem_Click);
this.recentSessionsToolStripMenuItem.Name = "recentSessionsToolStripMenuItem";
this.recentSessionsToolStripMenuItem.Size = new System.Drawing.Size(243, 22);
this.recentSessionsToolStripMenuItem.Text = "Recent Sessions";
//
// noneToolStripMenuItem1
//
this.noneToolStripMenuItem1.Name = "noneToolStripMenuItem1";
this.noneToolStripMenuItem1.Size = new System.Drawing.Size(152, 22);
this.noneToolStripMenuItem1.Text = "None";
//
// toolStripSeparator8
//
this.toolStripSeparator8.Name = "toolStripSeparator8";
this.toolStripSeparator8.Size = new System.Drawing.Size(149, 6);
//
// clearToolStripMenuItem1
//
this.clearToolStripMenuItem1.Name = "clearToolStripMenuItem1";
this.clearToolStripMenuItem1.Size = new System.Drawing.Size(152, 22);
this.clearToolStripMenuItem1.Text = "Clear";
//
// toolStripSeparator9
//
this.toolStripSeparator9.Name = "toolStripSeparator9";
this.toolStripSeparator9.Size = new System.Drawing.Size(240, 6);
//
// openSessionToolStripMenuItem
//
this.openSessionToolStripMenuItem.Image = global::BizHawk.MultiClient.Properties.Resources.OpenFile;
this.openSessionToolStripMenuItem.Name = "openSessionToolStripMenuItem";
this.openSessionToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O)));
this.openSessionToolStripMenuItem.Size = new System.Drawing.Size(243, 22);
this.openSessionToolStripMenuItem.Text = "&Open Session";
// //
// LuaConsole // LuaConsole
// //
@ -669,5 +687,7 @@
private System.Windows.Forms.ToolStripMenuItem noneToolStripMenuItem1; private System.Windows.Forms.ToolStripMenuItem noneToolStripMenuItem1;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator8; private System.Windows.Forms.ToolStripSeparator toolStripSeparator8;
private System.Windows.Forms.ToolStripMenuItem clearToolStripMenuItem1; private System.Windows.Forms.ToolStripMenuItem clearToolStripMenuItem1;
private System.Windows.Forms.ToolStripMenuItem helpToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem luaFunctionsListToolStripMenuItem;
} }
} }

View File

@ -25,7 +25,8 @@ namespace BizHawk.MultiClient
//TODO: restore column width on restore default settings //TODO: restore column width on restore default settings
//TODO: load scripts from recent scripts menu //TODO: load scripts from recent scripts menu
//TODO: context menu & main menu - Edit is grayed out if seperator is highlighted //TODO: context menu & main menu - Edit is grayed out if seperator is highlighted
//Free lua object when toggling a lua script off?
//Fix up lua functions list display
int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired
int defaultHeight; int defaultHeight;
@ -552,9 +553,20 @@ namespace BizHawk.MultiClient
OutputBox.Refresh(); OutputBox.Refresh();
} }
public void ClearOutputWindow()
{
OutputBox.Text = "";
OutputBox.Refresh();
}
private void openToolStripMenuItem_Click_1(object sender, EventArgs e) private void openToolStripMenuItem_Click_1(object sender, EventArgs e)
{ {
OpenLuaFile(); OpenLuaFile();
} }
private void luaFunctionsListToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show(LuaImp.LuaLibraryList);
}
} }
} }