更具体地说,完整的错误是
../../Scripts/LuaTest.lua:1: 'ï' 附近的意外符号
我已经LuaTest.lua
用不同的编辑器检查了文件以包含 Notepad++,但找不到任何额外/隐藏的字符。我不知道可能导致这种情况的原因。
旁注,我正在关注本指南:Godpatterns: Scripting with Lua in C#
这是主要的代码块:
class Program
{
static void Main(string[] args)
{
Lua lua = new Lua();
Program program = new Program();
// register our C# functions
lua.RegisterFunction("DanSays", program, program.GetType().GetMethod("DanSays"));
lua.RegisterFunction("ThorSays", program, program.GetType().GetMethod("ThorSays"));
lua.DoFile("../../Scripts/LuaTest.lua");
Console.ReadLine();
}
public void DanSays(string s)
{
Console.WriteLine("Dan Says > " + s);
}
public void ThorSays(string s)
{
Console.WriteLine("Thor says > " + s);
}
}
此外,这里是LuaTest.lua
DanSays("Hey, Thor!");
ThorSays("Hi Dan! You know Thursdays . . . ");
DanSays("*sigh* yeah, Thor, I know Thursdays.");
ThorSays("Named after me you know!");
DanSays("Yeah, I know.");