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

时间:2011-10-28 07:36:55

标签: c# lua luainterface

我想将WinForm对象传递给Lua,并在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

1 个答案:

答案 0 :(得分:0)

尝试:

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