如何将WinForm传递给Lua (LuaInterface)?

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

你的 OnLoad() 的第一行在 MSVC2005 上对我有效。 - sbk
1个回答

1

尝试:

m_lua["textBox1"] = this.textBox1;
m_lua.DoString("textBox1.Text = 'hello world'");

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接