我试图在我的 C#.NET 程序中实现 lua 脚本,但是当我执行代码时,其中一种方法没有被执行。
这是课程:
namespace Program1
{
public class LuaFunctions
{
Client Client { get; set; }
private Lua lua { get; set; }
public LuaFunctions(Client c) {
this.Client = c;
this.lua = new Lua();
registerFunctions();
}
public void ExecuteCode(string code)
{
this.lua.DoString(code);
}
private void registerFunctions()
{
lua.RegisterFunction("message", this, this.GetType().GetMethod("Message"));
lua.RegisterFunction("pname", this, this.GetType().GetMethod("playername"));
}
public void Message(string s)
{
System.Windows.Forms.MessageBox.Show(s);
}
public string playername()
{
return Client.Player.Name;
}
}
}
当我执行这行 lua 代码“message(pname)”时,它甚至没有尝试执行方法“playername()”来返回一些值,所以它在 DoString() 行中崩溃,因为“pname”正在“返回”无效的。