从C#中传递object到lua的一个问题

本来我是想从C#中把form对象传递到Lua里面去,然后在Lua中调用form下面的各个组件,比如textbox、button等,从而实现在Lua中控制C#中form界面的布局。

但是发现如下问题:

 1 //Form1.cs
2
3 class Form1
4 {
5 private System.Windows.Forms.TextBox textBox1;
6 private System.Windows.Forms.Button button1;
7
8 private void button1_Click(object sender, EventArgs e)
9 {
10 Lua m_lua = new Lua();
11 m_lua.DoFile("plugin.lua");
12 object[] objs = m_lua.GetFunction("OnLoad").Call(this, this.textBox1);
13 m_lua.Close();
14 }
15 }
1 --plugin.lua
2
3 function OnLoad(form, textbox)
4 textbox.Text = form.button1.Text -->Nil
5 textbox.Text = form.button1 -->希望获得button对象,结果发现这个是字符串
6 end


问题在于,本来我以为将form传递到lua中后,就可以在lua中调用form.button1及对象链,结果发现form.button1变成了字符串。

我猜测可能是只能传递单个对象,其属性和下属的子对象只能变成string了(toString())。

 

posted @ 2011-12-09 18:05  ifanxp  阅读(2757)  评论(0编辑  收藏  举报