I'm trying to implement lua scripting in my C#.NET program, but when I execute the code, one of the methods is not been executed.
Here is the class:
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;
}
}
}
When I execute this line of lua code "message(pname)" it does not even try to execute the method "playername()" to return some value, so it crashs in the DoString() line because "pname" is "returning" null.