Beispiel #1
0
        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();
        }
Beispiel #2
0
        } // 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);
        }
Beispiel #3
0
        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);
            }
        }
Beispiel #4
0
    } // 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;
    }
Beispiel #5
0
    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;
      }
    }