3

I want to pass a WinForm object to Lua, my code:

//Form1.cs

class Form1
{
  private System.Windows.Forms.TextBox textBox1;
  private System.Windows.Forms.Button button1;

  private void button1_Click(object sender, EventArgs e)
  {
    Lua m_lua = new Lua();
    m_lua.DoFile("plugin.lua");
    object[] objs = m_lua.GetFunction("OnLoad").Call(this, this.textBox1);
    m_lua.Close();
  }
}

--plugin.lua

function OnLoad(form, textbox)
  textbox.Text = form.button1.Text  -->Nil
  textbox.Text = form.button1       -->Expect an object, but got a string!
end
ouflak
  • 2,458
  • 10
  • 44
  • 49
ifan
  • 31
  • 2

1 Answers1

1

Try:

m_lua["textBox1"] = this.textBox1;
m_lua.DoString("textBox1.Text = 'hello world'");
mopenstein
  • 71
  • 1
  • 2