static void Main(string[] args) { Print.Welcome(); using (Neo.IronLua.Lua lua = new Neo.IronLua.Lua()) { var state = lua.CreateEnvironment(); string name = "test.lua"; state.DoChunk("message = 'Hello World!'", name); // create a variable in lua state.DoChunk("message = 'Hello World 2!'", name); // modify a variable in lua state.DoChunk(@" x = 1 y = 2 x, y = y, x print(x .. y) " , name); // modify a variable in lua Console.WriteLine(state["message"]); // access a variable in c# Console.WriteLine(state["x"]); // access a variable in c# Console.WriteLine(state["y"]); // access a variable in c# } Console.ReadLine(); }
} // proc ExecuteLuaIntf //private static Neo.IronLua.Lua lua = new Neo.IronLua.Lua(); private static long ExecuteNeoLua(int i, string sScript) { Stopwatch sw = new Stopwatch(); sw.Start(); using (Neo.IronLua.Lua lua = new Neo.IronLua.Lua()) { Neo.IronLua.LuaGlobal g = lua.CreateEnvironment(); g["test"] = new Action <int>(LuaTest); g["echo"] = new Func <object, object>(LuaEcho); DebugOut("NeoLua", i, g.DoChunk(sScript, "test")); } return(sw.ElapsedMilliseconds); }
private static double ExecuteNeoLuaCompiled(string sScript, int iLoops) { using (Neo.IronLua.Lua lua = new Neo.IronLua.Lua()) { Neo.IronLua.LuaChunk chunk = lua.CompileChunk(sScript, "test", new Neo.IronLua.LuaCompileOptions() { DebugEngine = debugNeoLua }); Neo.IronLua.LuaGlobal g = lua.CreateEnvironment(); g["test"] = new Action <int>(LuaTest); g["echo"] = new Func <object, object>(LuaEcho); Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < iLoops; i++) { DebugOut("NeoLua-C", i, g.DoChunk(chunk)); } return(sw.ElapsedMilliseconds / (double)iLoops); } }
} // proc ExecuteLuaIntf //private static Neo.IronLua.Lua lua = new Neo.IronLua.Lua(); private static long ExecuteNeoLua(int i, string sScript) { Stopwatch sw = new Stopwatch(); sw.Start(); using (Neo.IronLua.Lua lua = new Neo.IronLua.Lua()) { Neo.IronLua.LuaGlobal g = lua.CreateEnvironment(); g["test"] = new Action<int>(LuaTest); g["echo"] = new Func<object, object>(LuaEcho); DebugOut("NeoLua", i, g.DoChunk(sScript, "test")); } return sw.ElapsedMilliseconds; }
private static double ExecuteNeoLuaCompiled(string sScript, int iLoops) { using (Neo.IronLua.Lua lua = new Neo.IronLua.Lua()) { Neo.IronLua.LuaChunk chunk = lua.CompileChunk(sScript, "test", new Neo.IronLua.LuaCompileOptions() { DebugEngine = debugNeoLua }); Neo.IronLua.LuaGlobal g = lua.CreateEnvironment(); g["test"] = new Action<int>(LuaTest); g["echo"] = new Func<object, object>(LuaEcho); Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < iLoops; i++) DebugOut("NeoLua-C", i, g.DoChunk(chunk)); return sw.ElapsedMilliseconds / (double)iLoops; } }