3

我想将一个 WinForm 对象传递给 Lua,我的代码:

//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
4

1 回答 1

1

尝试:

m_lua["textBox1"] = this.textBox1;
m_lua.DoString("textBox1.Text = 'hello world'");
于 2011-11-23T02:01:51.057 回答