Beispiel #1
0
 /// <summary>
 /// Sets up a new Lua engine and environment.
 /// </summary>
 /// <returns>Returns the new Lua engine.</returns>
 public static Neo.IronLua.Lua Create()
 {
     IronLua     = new Neo.IronLua.Lua();
     Environment = IronLua.CreateEnvironment <LuaGlobal>();
     LuaCache    = new Dictionary <int, LuaChunk>();
     Ascertain(Environment);
     return(IronLua);
 }
Beispiel #2
0
        public static void Main(string[] args)
        {
            int iCurrentArg = 0;

            WriteText(ConsoleColor.Gray, "NeoLua Interactive Command"); Console.WriteLine();
            WriteText(ConsoleColor.DarkGray, "Version ");
            WriteText(ConsoleColor.White, String.Format("{0} ({1})", LuaGlobal.VersionString, Lua.Version));
            WriteText(ConsoleColor.DarkGray, " by neolithos");
            Console.WriteLine();
            Console.WriteLine();
            WriteText(ConsoleColor.DarkGray, "  source code at ");
            WriteText(ConsoleColor.Gray, "http://neolua.codeplex.com");
            Console.WriteLine();
            WriteText(ConsoleColor.DarkGray, "  supported from ");
            WriteText(ConsoleColor.Gray, "http://tecware-gmbh.de");
            Console.WriteLine();
            Console.WriteLine();
            WriteText(ConsoleColor.DarkGray, "  Write ':h' for help.");
            Console.WriteLine();
            Console.WriteLine();

            global = lua.CreateEnvironment <LuaCommandGlobal>();

            // change to the samples directory
#if DEBUG
            string sSamples = Path.GetFullPath(@"..\..\Samples");
            Debug.Listeners.Add(new ConsoleTraceListener());
#else
            string sSamples = Path.GetFullPath("Samples");
#endif
            if (Directory.Exists(sSamples))
            {
                Environment.CurrentDirectory = sSamples;
            }

            while (true)
            {
                string   sLine;
                Commands cmd;

                if (iCurrentArg < args.Length)
                {
                    cmd = ParseArgument(args[iCurrentArg++], out sLine);
                }
                else
                {
                    cmd = InputCommand(out sLine);
                }

                switch (cmd)
                {
                case Commands.List:
                    // list all variables in global
                    WriteText(ConsoleColor.DarkYellow, "List global:");
                    Console.WriteLine();
                    foreach (var c in global)
                    {
                        WriteVariable(c.Key, c.Value);
                    }
                    Console.WriteLine();
                    break;

                case Commands.Load:
                    RunScript(() => File.ReadAllText(Path.GetFullPath(sLine)), Path.GetFileName(sLine));
                    break;

                case Commands.Debug:
                    if (sLine == "trace")
                    {
                        WriteText(ConsoleColor.DarkYellow, "Compile emits traceline code, now."); Console.WriteLine();
                        debugEngine = debugConsole;
                    }
                    else if (sLine == Boolean.TrueString)
                    {
                        WriteText(ConsoleColor.DarkYellow, "Compile emits stack trace information and runtime functions, now."); Console.WriteLine();
                        debugEngine = LuaStackTraceDebugger.Default;
                    }
                    else
                    {
                        WriteText(ConsoleColor.DarkYellow, "Compile creates dynamic functions, now."); Console.WriteLine();
                        debugEngine = null;
                    }
                    Console.WriteLine();
                    break;

                case Commands.Environment:
                    WriteText(ConsoleColor.DarkYellow, "New environment created."); Console.WriteLine();
                    Console.WriteLine();
                    global = lua.CreateEnvironment <LuaCommandGlobal>();
                    break;

                case Commands.Cache:
                    lua.DumpRuleCaches(Console.Out);
                    Console.WriteLine();
                    break;

                case Commands.Help:
                    WriteText(ConsoleColor.DarkYellow, "Commands:"); Console.WriteLine();
                    WriteCommand(":q", "Exit the application.");
                    WriteCommand(":list", "Lists all global variables.");
                    WriteCommand(":load", "Loads the lua-script from a file.");
                    WriteCommand(":debugoff", "Tell the compiler to emit no debug informations.");
                    WriteCommand(":debugon", "Let the compiler emit debug informations.");
                    WriteCommand(":debugtrace", "Let the compiler emit trace line functionality.");
                    WriteCommand(":c", "Clears the current script buffer.");
                    WriteCommand(":env", "Create a fresh environment.");
                    WriteCommand(":cache", "Shows the content of the binder cache.");
                    Console.WriteLine();
                    break;

                case Commands.Run:
                    if (sLine.Length > 0)
                    {
                        RunScript(() => sLine, "line");
                    }
                    break;

                case Commands.Exit:
                    return;
                }
            }
        } // Main
Beispiel #3
0
 public LuaGeneral()
 {
     using var lua = new Neo.IronLua.Lua();
     var env = lua.CreateEnvironment();
 }