Esempio n. 1
0
        }         // func CompileChunk

        /// <summary>Create a code delegate without executing it.</summary>
        /// <param name="code">Code of the delegate..</param>
        /// <param name="options">Options for the compile process.</param>
        /// <param name="args">Arguments for the code block.</param>
        /// <returns>Compiled chunk.</returns>
        public LuaChunk CompileChunk(ILuaLexer code, LuaCompileOptions options, params KeyValuePair <string, Type>[] args)
        {
            if (code == null)
            {
                throw new ArgumentNullException(nameof(code));
            }
            return(CompileChunkCore(code, options, args));
        }         // func CompileChunk
Esempio n. 2
0
        }         // func CompileChunk

        /// <summary>Create a code delegate without executing it.</summary>
        /// <param name="code">Code of the delegate..</param>
        /// <param name="name">Name of the delegate</param>
        /// <param name="options">Options for the compile process.</param>
        /// <param name="args">Arguments for the code block.</param>
        /// <returns>Compiled chunk.</returns>
        public LuaChunk CompileChunk(string code, string name, LuaCompileOptions options, params KeyValuePair <string, Type>[] args)
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            using (var lex = LuaLexer.Create(name, new StringReader(code)))
                return(CompileChunkCore(lex, options, args));
        }         // func CompileChunk
Esempio n. 3
0
        }         // func CompileChunk

        /// <summary>Creates a code delegate or returns a single return constant.</summary>
        /// <param name="code"></param>
        /// <param name="options"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public object CompileOrReturnPrint(ILuaLexer code, LuaCompileOptions options, params KeyValuePair <string, Type>[] args)
        {
            if (IsConstantScript(code))             // eof
            {
                return(code.LookAhead.Typ == LuaToken.String
                                        ? code.LookAhead.Value
                                        : ParseNumber(code.LookAhead.Value));
            }
            else
            {
                return(CompileChunkCore(code, options, args));
            }
        }         // func CompileOrReturnPrint
Esempio n. 4
0
File: Lua.cs Progetto: tmkls/neolua
        }         // func CompileChunk

        internal LuaChunk CompileChunk(string sChunkName, LuaCompileOptions options, TextReader tr, IEnumerable <KeyValuePair <string, Type> > args)
        {
            if (String.IsNullOrEmpty(sChunkName))
            {
                throw new ArgumentNullException("chunkname");
            }
            if (options == null)
            {
                options = new LuaCompileOptions();
            }

            using (LuaLexer l = new LuaLexer(sChunkName, tr))
            {
                bool lRegisterMethods = options.DebugEngine != null && (options.DebugEngine.Level & LuaDebugLevel.RegisterMethods) == LuaDebugLevel.RegisterMethods;
                if (lRegisterMethods)
                {
                    BeginCompile();
                }
                try
                {
                    LambdaExpression expr = Parser.ParseChunk(this, options, true, l, null, typeof(LuaResult), args);

                    if (printExpressionTree != null)
                    {
                        printExpressionTree.WriteLine(Parser.ExpressionToString(expr));
                        printExpressionTree.WriteLine(new string('=', 79));
                    }

                    // compile the chunk
                    if (options.DebugEngine == null)
                    {
                        return(new LuaChunk(this, expr.Name, expr.Compile()));
                    }
                    else
                    {
                        return(options.DebugEngine.CreateChunk(this, expr));
                    }
                }
                finally
                {
                    if (lRegisterMethods)
                    {
                        EndCompile();
                    }
                }
            }
        }         // func CompileChunk
Esempio n. 5
0
        }         // func IsConstantScript

        internal LuaChunk CompileChunkCore(ILuaLexer lex, LuaCompileOptions options, IEnumerable <KeyValuePair <string, Type> > args)
        {
            if (options == null)
            {
                options = new LuaCompileOptions();
            }

            var registerMethods = options.DebugEngine != null && (options.DebugEngine.Level & LuaDebugLevel.RegisterMethods) == LuaDebugLevel.RegisterMethods;

            if (registerMethods)
            {
                BeginCompile();
            }
            try
            {
                var expr = Parser.ParseChunk(this, options, true, lex, null, typeof(LuaResult), args);

                if (printExpressionTree != null)
                {
                    printExpressionTree.WriteLine(Parser.ExpressionToString(expr));
                    printExpressionTree.WriteLine(new string('=', 79));
                }

                // compile the chunk
                return(options.DebugEngine == null
                                        ? new LuaChunk(this, expr.Name, expr.Compile())
                                        : options.DebugEngine.CreateChunk(this, expr));
            }
            finally
            {
                if (registerMethods)
                {
                    EndCompile();
                }
            }
        }         // func CompileChunkCore
Esempio n. 6
0
 /// <summary>Create a code delegate without executing it.</summary>
 /// <param name="fileName">File to parse.</param>
 /// <param name="options">Options for the compile process.</param>
 /// <param name="args">Arguments for the code block.</param>
 /// <returns>Compiled chunk.</returns>
 public LuaChunk CompileChunk(string fileName, LuaCompileOptions options, params KeyValuePair <string, Type>[] args)
 {
     using (var sr = new StreamReader(fileName))
         using (var lex = LuaLexer.Create(Path.GetFileName(fileName), sr, true))
             return(CompileChunkCore(lex, options, args));
 }         // func CompileChunk
Esempio n. 7
0
File: Lua.cs Progetto: tmkls/neolua
        }         // func CompileChunk

        /// <summary>Erzeugt ein Delegate aus dem Code, ohne ihn auszuführen.</summary>
        /// <param name="sCode">Code, der das Delegate darstellt.</param>
        /// <param name="sName">Name des Delegates</param>
        /// <param name="options">Options for the compile process.</param>
        /// <param name="args">Argumente</param>
        /// <returns>Compiled chunk.</returns>
        public LuaChunk CompileChunk(string sCode, string sName, LuaCompileOptions options, params KeyValuePair <string, Type>[] args)
        {
            return(CompileChunk(sName, options, new StringReader(sCode), args));
        }         // func CompileChunk
Esempio n. 8
0
File: Lua.cs Progetto: tmkls/neolua
        }         // func CreateEnvironment

        #endregion

        #region -- Compile ----------------------------------------------------------------

        /// <summary>Erzeugt ein Delegate aus dem Code, ohne ihn auszuführen.</summary>
        /// <param name="tr">Inhalt</param>
        /// <param name="sName">Name der Datei</param>
        /// <param name="options">Options for the compile process.</param>
        /// <param name="args">Parameter für den Codeblock</param>
        /// <returns>Compiled chunk.</returns>
        public LuaChunk CompileChunk(TextReader tr, string sName, LuaCompileOptions options, params KeyValuePair <string, Type>[] args)
        {
            return(CompileChunk(sName, options, tr, args));
        }         // func CompileChunk
Esempio n. 9
0
 /// <summary>Create a code delegate without executing it.</summary>
 /// <param name="code">Code of the delegate..</param>
 /// <param name="name">Name of the delegate</param>
 /// <param name="options">Options for the compile process.</param>
 /// <param name="args">Arguments for the code block.</param>
 /// <returns>Compiled chunk.</returns>
 public LuaChunk CompileChunk(string code, string name, LuaCompileOptions options, params KeyValuePair <string, Type>[] args)
 => CompileChunk(name, options, new StringReader(code), args);
Esempio n. 10
0
        }         // func CompileChunk

        /// <summary>Create a code delegate without executing it.</summary>
        /// <param name="tr">Inhalt</param>
        /// <param name="name">Name der Datei</param>
        /// <param name="options">Options for the compile process.</param>
        /// <param name="args">Arguments for the code block.</param>
        /// <returns>Compiled chunk.</returns>
        public LuaChunk CompileChunk(TextReader tr, string name, LuaCompileOptions options, params KeyValuePair <string, Type>[] args)
        => CompileChunk(name, options, tr, args);
Esempio n. 11
0
 /// <summary>Create a code delegate without executing it.</summary>
 /// <param name="fileName">File to parse.</param>
 /// <param name="options">Options for the compile process.</param>
 /// <param name="args">Arguments for the code block.</param>
 /// <returns>Compiled chunk.</returns>
 public LuaChunk CompileChunk(string fileName, LuaCompileOptions options, params KeyValuePair <string, Type>[] args)
 {
     using (var sr = new StreamReader(fileName))
         return(CompileChunk(Path.GetFileName(fileName), options, sr, args));
 }         // func CompileChunk
Esempio n. 12
0
 /// <summary>Erzeugt ein Delegate aus dem Code, ohne ihn auszuführen.</summary>
 /// <param name="lua"></param>
 /// <param name="sFileName">Dateiname die gelesen werden soll.</param>
 /// <param name="options">Options for the compile process.</param>
 /// <param name="args">Parameter für den Codeblock</param>
 /// <returns>Compiled chunk.</returns>
 public static LuaChunk CompileChunk(this Lua lua, string sFileName, LuaCompileOptions options, params KeyValuePair <string, Type>[] args)
 {
     using (StreamReader sr = new StreamReader(sFileName))
         return(lua.CompileChunk(sr, Path.GetFileName(sFileName), options, args));
 }         // func CompileChunk