diff --git a/BizHawk.MultiClient/BizHawk.MultiClient.csproj b/BizHawk.MultiClient/BizHawk.MultiClient.csproj
index 8c876c1dce..629a487558 100644
--- a/BizHawk.MultiClient/BizHawk.MultiClient.csproj
+++ b/BizHawk.MultiClient/BizHawk.MultiClient.csproj
@@ -332,6 +332,9 @@
HexFind.cs
+
+ Component
+
Form
diff --git a/BizHawk.MultiClient/LuaImplementation.cs b/BizHawk.MultiClient/LuaImplementation.cs
index 2e56b82c36..2cafe64943 100644
--- a/BizHawk.MultiClient/LuaImplementation.cs
+++ b/BizHawk.MultiClient/LuaImplementation.cs
@@ -411,6 +411,7 @@ namespace BizHawk.MultiClient
"newform",
"destroy",
"destroyall",
+ "button",
};
/****************************************************/
@@ -423,7 +424,14 @@ namespace BizHawk.MultiClient
public void console_output(object lua_input)
{
- Global.MainForm.LuaConsole1.WriteToOutputWindow(lua_input.ToString());
+ if (lua_input == null)
+ {
+ Global.MainForm.LuaConsole1.WriteToOutputWindow("NULL");
+ }
+ else
+ {
+ Global.MainForm.LuaConsole1.WriteToOutputWindow(lua_input.ToString());
+ }
}
public void console_log(object lua_input)
@@ -1674,7 +1682,6 @@ namespace BizHawk.MultiClient
public bool forms_destroy(object handle)
{
- //TODO: try/catch, error handling, etc
IntPtr ptr = new IntPtr(LuaInt(handle));
foreach (LuaWinform form in LuaForms)
{
@@ -1696,5 +1703,39 @@ namespace BizHawk.MultiClient
LuaForms.Remove(form);
}
}
+
+ public int forms_button(object form_handle, object caption, LuaFunction lua_event, object X = null, object Y = null)
+ {
+ IntPtr ptr = new IntPtr(LuaInt(form_handle));
+ foreach (LuaWinform form in LuaForms)
+ {
+ if (form.Handle == ptr)
+ {
+ LuaButton button = new LuaButton();
+ button.Text = caption.ToString();
+ form.Controls.Add(button);
+ form.Control_Events.Add(new LuaWinform.Lua_Event(button.Handle, lua_event));
+
+ //button.Click += new System.EventHandler(button.DoLuaClick);
+ try
+ {
+ if (X != null && Y != null)
+ {
+ int x = LuaInt(X);
+ int y = LuaInt(Y);
+ button.Location = new Point(x, y);
+ }
+ }
+ catch
+ {
+ //Do nothing
+ }
+
+ return (int)button.Handle;
+ }
+ }
+
+ return 0;
+ }
}
}
diff --git a/BizHawk.MultiClient/tools/LuaButton.cs b/BizHawk.MultiClient/tools/LuaButton.cs
new file mode 100644
index 0000000000..9ec03cc955
--- /dev/null
+++ b/BizHawk.MultiClient/tools/LuaButton.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+
+namespace BizHawk.MultiClient.tools
+{
+ class LuaButton : Button
+ {
+ private void DoLuaClick(object sender, EventArgs e)
+ {
+ LuaWinform parent = this.Parent as LuaWinform;
+ parent.DoLuaEvent(this.Handle);
+ }
+
+ protected override void OnClick(EventArgs e)
+ {
+ DoLuaClick(this, e);
+ base.OnClick(e);
+ }
+ }
+}
diff --git a/BizHawk.MultiClient/tools/LuaWinform.Designer.cs b/BizHawk.MultiClient/tools/LuaWinform.Designer.cs
index 004a29b4ea..97924bcf96 100644
--- a/BizHawk.MultiClient/tools/LuaWinform.Designer.cs
+++ b/BizHawk.MultiClient/tools/LuaWinform.Designer.cs
@@ -38,7 +38,7 @@
this.ClientSize = new System.Drawing.Size(284, 262);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "LuaWinform";
- this.Text = "LuaWinform";
+ this.Text = "Lua Dialog";
this.Load += new System.EventHandler(this.LuaWinform_Load);
this.ResumeLayout(false);
diff --git a/BizHawk.MultiClient/tools/LuaWinform.cs b/BizHawk.MultiClient/tools/LuaWinform.cs
index 770d173338..913ad6b663 100644
--- a/BizHawk.MultiClient/tools/LuaWinform.cs
+++ b/BizHawk.MultiClient/tools/LuaWinform.cs
@@ -12,7 +12,7 @@ namespace BizHawk.MultiClient.tools
{
public partial class LuaWinform : Form
{
- public List Events = new List();
+ public List Control_Events = new List();
public LuaWinform()
{
@@ -29,5 +29,29 @@ namespace BizHawk.MultiClient.tools
{
Global.MainForm.LuaConsole1.LuaImp.WindowClosed(Handle);
}
+
+ public void DoLuaEvent(IntPtr handle)
+ {
+ foreach (Lua_Event l_event in Control_Events)
+ {
+ if (l_event.Control == handle)
+ {
+ l_event.Event.Call();
+ }
+ }
+ }
+
+ public class Lua_Event
+ {
+ public LuaFunction Event;
+ public IntPtr Control;
+
+ public Lua_Event() { }
+ public Lua_Event(IntPtr handle, LuaFunction lfunction)
+ {
+ Event = lfunction;
+ Control = handle;
+ }
+ }
}
}