diff --git a/NeoCmd/Program.cs b/NeoCmd/Program.cs index 646bf81..06f72b2 100644 --- a/NeoCmd/Program.cs +++ b/NeoCmd/Program.cs @@ -187,7 +187,7 @@ protected override void OnFrameExit() private static Lua lua = new Lua(); // create lua script compiler private static LuaGlobal global; - private static ILuaDebug debugEngine = Lua.DefaultDebugEngine; + private static ILuaDebug debugEngine = Lua.DefaultDebugEngine.DebugEngine; private static ILuaDebug debugConsole = new LuaTraceLineConsoleDebugger(); private static void WriteText(ConsoleColor textColor, string sText) @@ -423,7 +423,7 @@ private static void RunScript(Func code, string sName) sw.Start(); // compile chunk - LuaChunk c = lua.CompileChunk(code(), sName, debugEngine); + LuaChunk c = lua.CompileChunk(code(), sName, new LuaCompileOptions() { DebugEngine = debugEngine }); string sCompileTime = String.Format("{0:N0} ms", sw.ElapsedMilliseconds); sw.Reset(); @@ -548,7 +548,7 @@ public static void Main(string[] args) else if (sLine == Boolean.TrueString) { WriteText(ConsoleColor.DarkYellow, "Compile emits stack trace information and runtime functions, now."); Console.WriteLine(); - debugEngine = Lua.DefaultDebugEngine; + debugEngine = Lua.DefaultDebugEngine.DebugEngine; } else { diff --git a/NeoLua/Lua.cs b/NeoLua/Lua.cs index f42f85f..4573c05 100644 --- a/NeoLua/Lua.cs +++ b/NeoLua/Lua.cs @@ -46,6 +46,76 @@ public enum LuaFloatType : byte #endregion + #region -- enum LuaSandboxResult ---------------------------------------------------- + + /////////////////////////////////////////////////////////////////////////////// + /// Defines the sandbox type + public enum LuaSandboxResult + { + /// No sandbox + None, + /// Access is not allowed. + Restrict, + /// Check the access during runtime. + Dynamic + } // enum LuaSandboxResult + + #endregion + + #region -- class LuaCompileOptions -------------------------------------------------- + + /////////////////////////////////////////////////////////////////////////////// + /// Defines option for the parse and compile of a script. + public class LuaCompileOptions + { + /// Action on access diened. + /// + protected virtual Expression RestrictAccess() + { + return Expression.Throw(Expression.New(typeof(UnauthorizedAccessException))); + } // func RestrictAccess + + /// Most core method, that gets called to sandbox a value. + /// Expression, that should be sandboxed. + /// Optional: Instance, that was called to get the expression. + /// Optional: Name of the member that was used to resolve the expression. + /// Sandboxed expression + protected internal virtual Expression SandboxCore(Expression expression, Expression instance, string sMember) + { + switch (Sandbox(expression.Type, instance == null ? null : instance.Type, sMember)) + { + case LuaSandboxResult.Dynamic: + if (DynamicSandbox == null) + return expression; + else + return LuaEmit.Convert(null, Expression.Invoke(Expression.Constant(DynamicSandbox), expression), typeof(object), expression.Type, false); + + case LuaSandboxResult.Restrict: + return RestrictAccess(); + + default: + return expression; + } + } // func SandboxCore + + /// Higher level method to restict access to types. + /// Type of the sandbox value + /// Optional: Instance, that was called to get the expression. + /// Optional: Name of the member that was used to resolve the expression. + /// Sandbox action + protected virtual LuaSandboxResult Sandbox(Type expressionType, Type instanceType, string sMember) + { + return DynamicSandbox == null ? LuaSandboxResult.None : LuaSandboxResult.Dynamic; + } // func Sandbox + + /// Gets called if the sandbox will resolved during runtime. + public Func DynamicSandbox { get; set; } + /// Set this member to compile the script with Debug-Infos. + public ILuaDebug DebugEngine { get; set; } + } // class LuaCompileOptions + + #endregion + /////////////////////////////////////////////////////////////////////////////// /// Manages the Lua-Script-Environment. At the time it holds the /// binder cache between the compiled scripts. @@ -106,48 +176,51 @@ public virtual void Clear() /// Erzeugt ein Delegate aus dem Code, ohne ihn auszuführen. /// Dateiname die gelesen werden soll. - /// Compile with debug infos + /// Options for the compile process. /// Parameter für den Codeblock /// Compiled chunk. - public LuaChunk CompileChunk(string sFileName, ILuaDebug debug, params KeyValuePair[] args) + public LuaChunk CompileChunk(string sFileName, LuaCompileOptions options, params KeyValuePair[] args) { - return CompileChunk(sFileName, debug, new StreamReader(sFileName), args); + return CompileChunk(sFileName, options, new StreamReader(sFileName), args); } // func CompileChunk /// Erzeugt ein Delegate aus dem Code, ohne ihn auszuführen. /// Inhalt /// Name der Datei - /// Compile with debug infos + /// Options for the compile process. /// Parameter für den Codeblock /// Compiled chunk. - public LuaChunk CompileChunk(TextReader tr, string sName, ILuaDebug debug, params KeyValuePair[] args) + public LuaChunk CompileChunk(TextReader tr, string sName, LuaCompileOptions options, params KeyValuePair[] args) { - return CompileChunk(sName, debug, tr, args); + return CompileChunk(sName, options, tr, args); } // func CompileChunk /// Erzeugt ein Delegate aus dem Code, ohne ihn auszuführen. /// Code, der das Delegate darstellt. /// Name des Delegates - /// Compile with debug infos + /// Options for the compile process. /// Argumente /// Compiled chunk. - public LuaChunk CompileChunk(string sCode, string sName, ILuaDebug debug, params KeyValuePair[] args) + public LuaChunk CompileChunk(string sCode, string sName, LuaCompileOptions options, params KeyValuePair[] args) { - return CompileChunk(sName, debug, new StringReader(sCode), args); + return CompileChunk(sName, options, new StringReader(sCode), args); } // func CompileChunk - internal LuaChunk CompileChunk(string sChunkName, ILuaDebug debug, TextReader tr, IEnumerable> args) + internal LuaChunk CompileChunk(string sChunkName, LuaCompileOptions options, TextReader tr, IEnumerable> args) { if (String.IsNullOrEmpty(sChunkName)) throw new ArgumentNullException("chunkname"); + if (options == null) + options = new LuaCompileOptions(); using (LuaLexer l = new LuaLexer(sChunkName, tr)) { - if (debug != null && (debug.Level & LuaDebugLevel.RegisterMethods) == LuaDebugLevel.RegisterMethods) + bool lRegisterMethods = options.DebugEngine != null && (options.DebugEngine.Level & LuaDebugLevel.RegisterMethods) == LuaDebugLevel.RegisterMethods; + if (lRegisterMethods) BeginCompile(); try { - LambdaExpression expr = Parser.ParseChunk(this, debug == null ? LuaDebugLevel.None : debug.Level, true, l, null, typeof(LuaResult), args); + LambdaExpression expr = Parser.ParseChunk(this, options, true, l, null, typeof(LuaResult), args); if (lPrintExpressionTree) { @@ -156,14 +229,14 @@ internal LuaChunk CompileChunk(string sChunkName, ILuaDebug debug, TextReader tr } // compile the chunk - if (debug == null) + if (options.DebugEngine == null) return new LuaChunk(this, expr.Name, expr.Compile()); else - return debug.CreateChunk(this, expr); + return options.DebugEngine.CreateChunk(this, expr); } finally { - if (debug != null && (debug.Level & LuaDebugLevel.RegisterMethods) == LuaDebugLevel.RegisterMethods) + if (lRegisterMethods) EndCompile(); } } @@ -180,7 +253,7 @@ public Delegate CreateLambda(string sName, string sCode, Type typeDelegate, Type { using (LuaLexer l = new LuaLexer(sName, new StringReader(sCode))) { - LambdaExpression expr = Parser.ParseChunk(this, LuaDebugLevel.None, false, l, typeDelegate, returnType, arguments); + LambdaExpression expr = Parser.ParseChunk(this, new LuaCompileOptions(), false, l, typeDelegate, returnType, arguments); if (lPrintExpressionTree) { @@ -402,7 +475,7 @@ public string StandardPackagesPath // -- Static -------------------------------------------------------------- private static object lockDefaultDebugEngine = new object(); - private static ILuaDebug defaultDebugEngine = null; + private static LuaCompileOptions defaultDebugEngine = null; private static int iRegisteredChunkLock = 0; private static Dictionary registeredChunks = new Dictionary(); @@ -492,13 +565,13 @@ public static LuaChunk GetChunkFromMethodInfo(MethodBase mi) #endregion /// Returns a default StackTrace-Debug Engine - public static ILuaDebug DefaultDebugEngine + public static LuaCompileOptions DefaultDebugEngine { get { lock (lockDefaultDebugEngine) if (defaultDebugEngine == null) - defaultDebugEngine = new LuaStackTraceDebugger(); + defaultDebugEngine = new LuaCompileOptions() { DebugEngine = new LuaStackTraceDebugger() }; return defaultDebugEngine; } } // prop DefaultDebugEngine diff --git a/NeoLua/LuaDebug.cs b/NeoLua/LuaDebug.cs index 1ef0048..d7ededf 100644 --- a/NeoLua/LuaDebug.cs +++ b/NeoLua/LuaDebug.cs @@ -66,6 +66,8 @@ public interface ILuaDebugInfo #endregion + #region -- class LuaStackTraceDebugger ---------------------------------------------- + /////////////////////////////////////////////////////////////////////////////// /// Debugger that creates the methods as dynamic assembly, with them /// it is possible to retrieve exact stacktraces. This debugger is good if @@ -464,4 +466,6 @@ private static AssemblyName GetLuaDynamicName() } } // func GetLuaDynamicName } // class StackTraceDebugger + + #endregion } diff --git a/NeoLua/Parser.Emit.cs b/NeoLua/Parser.Emit.cs index 19ccdab..3cad14b 100644 --- a/NeoLua/Parser.Emit.cs +++ b/NeoLua/Parser.Emit.cs @@ -123,9 +123,14 @@ private static Expression ConcatOperationExpression(Lua runtime, Token tStart, E } } // func ConcatOperationExpression - private static Expression MemberGetExpression(Lua runtime, Token tStart, Expression instance, string sMember, bool lMethodMember) + private static Expression MemberGetSandbox(Scope scope, Expression getMember, Expression instance, string sMember) { - return SafeExpression(() => LuaEmit.GetMember(runtime, instance, instance.Type, sMember, false, true), tStart); + return scope.Options.SandboxCore(getMember, instance, sMember); + } // func MemberGetSandbox + + private static Expression MemberGetExpression(Scope scope, Token tStart, Expression instance, string sMember) + { + return MemberGetSandbox(scope, SafeExpression(() => LuaEmit.GetMember(scope.Runtime, instance, instance.Type, sMember, false, true), tStart), instance, sMember); } // func MemberGetExpression private static Expression MemberSetExpression(Lua runtime, Token tStart, Expression instance, string sMember, bool lMethodMember, Expression set) @@ -144,7 +149,7 @@ private static Expression MemberSetExpression(Lua runtime, Token tStart, Express return SafeExpression(() => LuaEmit.SetMember(runtime, instance, instance.Type, sMember, false, set, set.Type, true), tStart); } // func MemberSetExpression - private static Expression IndexGetExpression(Lua runtime, Token tStart, Expression instance, Expression[] indexes) + private static Expression IndexGetExpression(Scope scope, Token tStart, Expression instance, Expression[] indexes) { if (instance.Type == typeof(LuaTable)) { @@ -154,45 +159,65 @@ private static Expression IndexGetExpression(Lua runtime, Token tStart, Expressi if (LuaTable.IsIndexKey(arg.Type)) // integer access { - return Expression.Call(instance, Lua.TableGetValueKeyIntMethodInfo, - ConvertExpression(runtime, tStart, arg, typeof(int)), - Expression.Constant(false) + return MemberGetSandbox( + scope, + Expression.Call(instance, Lua.TableGetValueKeyIntMethodInfo, + ConvertExpression(scope.Runtime, tStart, arg, typeof(int)), + Expression.Constant(false) + ), + instance, null ); } else if (arg.Type == typeof(string)) // member access { - return Expression.Call(instance, Lua.TableGetValueKeyStringMethodInfo, - arg, - Expression.Constant(false), - Expression.Constant(false) + return MemberGetSandbox( + scope, + Expression.Call(instance, Lua.TableGetValueKeyStringMethodInfo, + arg, + Expression.Constant(false), + Expression.Constant(false) + ), + instance, null ); } else // key access { - return Expression.Call(instance, Lua.TableGetValueKeyObjectMethodInfo, - ConvertObjectExpression(runtime, tStart, arg, true), - Expression.Constant(false) + return MemberGetSandbox( + scope, + Expression.Call(instance, Lua.TableGetValueKeyObjectMethodInfo, + ConvertObjectExpression(scope.Runtime, tStart, arg, true), + Expression.Constant(false) + ), + instance, null ); } } else { - return Expression.Call(instance, Lua.TableGetValueKeyListMethodInfo, - Expression.NewArrayInit(typeof(object), from i in indexes select ConvertObjectExpression(runtime, tStart, i, true)), - Expression.Constant(false) + return MemberGetSandbox( + scope, + Expression.Call(instance, Lua.TableGetValueKeyListMethodInfo, + Expression.NewArrayInit(typeof(object), from i in indexes select ConvertObjectExpression(scope.Runtime, tStart, i, true)), + Expression.Constant(false) + ), + instance, null ); } } else if (instance.Type == typeof(LuaResult) && indexes.Length == 1) { - return Expression.MakeIndex( - instance, - Lua.ResultIndexPropertyInfo, - new Expression[] { ConvertExpression(runtime, tStart, indexes[0], typeof(int)) } + return MemberGetSandbox( + scope, + Expression.MakeIndex( + instance, + Lua.ResultIndexPropertyInfo, + new Expression[] { ConvertExpression(scope.Runtime, tStart, indexes[0], typeof(int)) } + ), + instance, null ); } else - return SafeExpression(() => LuaEmit.GetIndex(runtime, instance, indexes, getExpressionFunction, getExpressionTypeFunction, true), tStart); + return MemberGetSandbox(scope, SafeExpression(() => LuaEmit.GetIndex(scope.Runtime, instance, indexes, getExpressionFunction, getExpressionTypeFunction, true), tStart), instance, null); } // func IndexGetExpression private static Expression IndexSetExpression(Lua runtime, Token tStart, Expression instance, Expression[] indexes, Expression set) @@ -241,7 +266,7 @@ private static Expression IndexSetExpression(Lua runtime, Token tStart, Expressi return SafeExpression(() => LuaEmit.SetIndex(runtime, instance, indexes, set, getExpressionFunction, getExpressionTypeFunction, true), tStart); } // func IndexSetExpression - private static Expression InvokeExpression(Lua runtime, Token tStart, Expression instance, InvokeResult result, Expression[] arguments, bool lParse) + private static Expression InvokeExpression(Scope scope, Token tStart, Expression instance, InvokeResult result, Expression[] arguments, bool lParse) { MethodInfo mi; ConstantExpression constInstance = instance as ConstantExpression; @@ -257,7 +282,7 @@ private static Expression InvokeExpression(Lua runtime, Token tStart, Expression if (ci == null && !type.IsValueType) throw ParseError(tStart, String.Format(Properties.Resources.rsMemberNotResolved, type.Name, "ctor")); - return SafeExpression(() => LuaEmit.BindParameter(runtime, + return SafeExpression(() => LuaEmit.BindParameter(scope.Runtime, args => ci == null ? Expression.New(type) : Expression.New(ci, args), ci == null ? new ParameterInfo[0] : ci.GetParameters(), arguments, @@ -266,44 +291,44 @@ private static Expression InvokeExpression(Lua runtime, Token tStart, Expression else if (LuaEmit.IsDynamicType(instance.Type)) { // fallback is a dynamic call - return EnsureInvokeResult(runtime, tStart, - Expression.Dynamic(runtime.GetInvokeBinder(new CallInfo(arguments.Length)), + return EnsureInvokeResult(scope, tStart, + Expression.Dynamic(scope.Runtime.GetInvokeBinder(new CallInfo(arguments.Length)), typeof(object), - new Expression[] { ConvertExpression(runtime, tStart, instance, typeof(object)) }.Concat( + new Expression[] { ConvertExpression(scope.Runtime, tStart, instance, typeof(object)) }.Concat( from c in arguments select Lua.EnsureType(c, typeof(object)) ) ), - result + result, instance, null ); } else if (typeof(Delegate).IsAssignableFrom(instance.Type) && // test if the type is assignable from delegate (mi = instance.Type.GetMethod("Invoke")) != null) // Search the Invoke method for the arguments { - return EnsureInvokeResult(runtime, tStart, + return EnsureInvokeResult(scope, tStart, SafeExpression(() => LuaEmit.BindParameter( - runtime, + scope.Runtime, args => Expression.Invoke(instance, args), mi.GetParameters(), arguments, getExpressionFunction, getExpressionTypeFunction, true), tStart), - result + result, instance, null ); } else throw ParseError(tStart, LuaEmitException.GetMessageText(LuaEmitException.InvokeNoDelegate, instance.Type.Name)); } // func InvokeExpression - private static Expression InvokeMemberExpression(Lua runtime, Token tStart, Expression instance, string sMember, InvokeResult result, Expression[] arguments) + private static Expression InvokeMemberExpression(Scope scope, Token tStart, Expression instance, string sMember, InvokeResult result, Expression[] arguments) { if (LuaEmit.IsDynamicType(instance.Type)) { - return EnsureInvokeResult(runtime, tStart, - Expression.Dynamic(runtime.GetInvokeMemberBinder(sMember, new CallInfo(arguments.Length)), typeof(object), - new Expression[] { ConvertExpression(runtime, tStart, instance, typeof(object)) }.Concat( + return EnsureInvokeResult(scope, tStart, + Expression.Dynamic(scope.Runtime.GetInvokeMemberBinder(sMember, new CallInfo(arguments.Length)), typeof(object), + new Expression[] { ConvertExpression(scope.Runtime, tStart, instance, typeof(object)) }.Concat( from c in arguments select Lua.EnsureType(c, typeof(object)) ).ToArray() ), - result + result, instance, sMember ); } else @@ -316,14 +341,9 @@ from c in arguments select Lua.EnsureType(c, typeof(object)) true); if (method != null) - { - return SafeExpression(() => EnsureInvokeResult(runtime, tStart, - InvokeMemberExpressionBind(method, runtime, instance, arguments), - result - ), tStart); - } + return EnsureInvokeResult(scope, tStart, SafeExpression(() => InvokeMemberExpressionBind(method, scope.Runtime, instance, arguments), tStart), result, instance, sMember); else - return InvokeMemberExpressionDynamic(runtime, tStart, instance, sMember, result, arguments); + return InvokeMemberExpressionDynamic(scope, tStart, instance, sMember, result, arguments); } } // func InvokeMemberExpression @@ -349,29 +369,29 @@ from a in arguments select Lua.EnsureType(a, typeof(object)) } } // func InvokeMemberExpressionBind - private static Expression InvokeMemberExpressionDynamic(Lua runtime, Token tStart, Expression instance, string sMember, InvokeResult result, Expression[] arguments) + private static Expression InvokeMemberExpressionDynamic(Scope scope, Token tStart, Expression instance, string sMember, InvokeResult result, Expression[] arguments) { - return EnsureInvokeResult(runtime, tStart, - Expression.Dynamic(runtime.GetInvokeMemberBinder(sMember, new CallInfo(arguments.Length)), typeof(object), - new Expression[] { ConvertExpression(runtime, tStart, instance, typeof(object)) }.Concat(from a in arguments select Lua.EnsureType(a, typeof(object))).ToArray() + return EnsureInvokeResult(scope, tStart, + Expression.Dynamic(scope.Runtime.GetInvokeMemberBinder(sMember, new CallInfo(arguments.Length)), typeof(object), + new Expression[] { ConvertExpression(scope.Runtime, tStart, instance, typeof(object)) }.Concat(from a in arguments select Lua.EnsureType(a, typeof(object))).ToArray() ), - result + result, instance, sMember ); } // func InvokeMemberExpressionDynamic - private static Expression EnsureInvokeResult(Lua runtime, Token tStart, Expression expr, InvokeResult result) + private static Expression EnsureInvokeResult(Scope scope, Token tStart, Expression expr, InvokeResult result, Expression instance, string sMember) { switch (result) { case InvokeResult.LuaResult: - return ConvertExpression(runtime, tStart, expr, typeof(LuaResult)); + return ConvertExpression(scope.Runtime, tStart, expr, typeof(LuaResult)); case InvokeResult.Object: if (LuaEmit.IsDynamicType(expr.Type)) - return Expression.Dynamic(runtime.GetConvertBinder(typeof(object)), typeof(object), ConvertExpression(runtime, tStart, expr, typeof(object))); + return MemberGetSandbox(scope, Expression.Dynamic(scope.Runtime.GetConvertBinder(typeof(object)), typeof(object), ConvertExpression(scope.Runtime, tStart, expr, typeof(object))), instance, sMember); else - return expr; + return MemberGetSandbox(scope, expr, instance, sMember); default: - return expr; + return MemberGetSandbox(scope, expr, instance, sMember); } } // func EnsureInvokeResult diff --git a/NeoLua/Parser.cs b/NeoLua/Parser.cs index 72d81ab..8b04a0c 100644 --- a/NeoLua/Parser.cs +++ b/NeoLua/Parser.cs @@ -165,6 +165,8 @@ public virtual Expression ExpressionBlock public virtual Lua Runtime { get { return parent.Runtime; } } /// Emit-Debug-Information public virtual LuaDebugLevel EmitDebug { get { return parent.EmitDebug; } } + /// Options + public virtual LuaCompileOptions Options { get { return parent.Options; } } /// DebugInfo on expression level public bool EmitExpressionDebug { get { return (EmitDebug & LuaDebugLevel.Expression) != 0; } } /// Return type of the current Lambda-Scope @@ -342,24 +344,28 @@ public LabelTarget ReturnLabel private class GlobalScope : LambdaScope { private Lua runtime; + private LuaCompileOptions options; private LuaDebugLevel debug; /// Global parse-scope /// Runtime and binder of the global scope. - /// + /// /// /// - public GlobalScope(Lua runtime, LuaDebugLevel debug, Type returnType, Expression returnDefaultValue) + public GlobalScope(Lua runtime, LuaCompileOptions options, Type returnType, Expression returnDefaultValue) : base(null, returnType, returnDefaultValue) { this.runtime = runtime; - this.debug = debug; + this.options = options; + this.debug = options.DebugEngine == null ? LuaDebugLevel.None : options.DebugEngine.Level; } // ctor /// Access to the binders public override Lua Runtime { get { return runtime; } } /// Emit-Debug-Information public override LuaDebugLevel EmitDebug { get { return debug; } } + /// Options + public override LuaCompileOptions Options { get { return options; } } } // class GlobalScope #endregion @@ -418,14 +424,14 @@ public Expression GenerateGet(Scope scope, InvokeResult result) Indices[Indices.Length - 1] = WrapDebugInfo(scope.EmitExpressionDebug, true, Position, Position, Indices[Indices.Length - 1]); // Let the type as it is } - Instance = IndexGetExpression(scope.Runtime, Position, Instance, Indices); + Instance = IndexGetExpression(scope, Position, Instance, Indices); Indices = null; } else if (Instance != null && Member != null && Indices == null && Arguments == null) { // Convert the member to an instance Instance = WrapDebugInfo(scope.EmitExpressionDebug, true, Position, Position, Instance); - Instance = MemberGetExpression(scope.Runtime, Position, Instance, Member, MethodMember); + Instance = MemberGetExpression(scope, Position, Instance, Member); Member = null; MethodMember = false; } @@ -444,9 +450,9 @@ public Expression GenerateGet(Scope scope, InvokeResult result) Instance = WrapDebugInfo(scope.EmitExpressionDebug, true, Position, Position, Instance); if (String.IsNullOrEmpty(Member)) - Instance = InvokeExpression(scope.Runtime, Position, Instance, result, Arguments, true); + Instance = InvokeExpression(scope, Position, Instance, result, Arguments, true); else - Instance = InvokeMemberExpression(scope.Runtime, Position, Instance, Member, result, Arguments); + Instance = InvokeMemberExpression(scope, Position, Instance, Member, result, Arguments); Member = null; MethodMember = false; @@ -479,19 +485,19 @@ public void SetMember(Token tMember, bool lMethod) /// Parses the chunk to an function. /// Binder - /// Compile the script with debug information. + /// Compile options for the script. /// Creates the _G parameter. /// Lexer for the code. /// Type for the delegate. null, for an automatic type /// Defines the return type of the chunk. /// Arguments of the function. /// Expression-Tree for the code. - public static LambdaExpression ParseChunk(Lua runtime, LuaDebugLevel debug, bool lHasEnvironment, LuaLexer code, Type typeDelegate, Type returnType, IEnumerable> args) + public static LambdaExpression ParseChunk(Lua runtime, LuaCompileOptions options, bool lHasEnvironment, LuaLexer code, Type typeDelegate, Type returnType, IEnumerable> args) { List parameters = new List(); if (returnType == null) returnType = typeof(LuaResult); - var globalScope = new GlobalScope(runtime, debug, returnType, returnType == typeof(LuaResult) ? Expression.Property(null, Lua.ResultEmptyPropertyInfo) : null); + var globalScope = new GlobalScope(runtime, options, returnType, returnType == typeof(LuaResult) ? Expression.Property(null, Lua.ResultEmptyPropertyInfo) : null); // Registers the global LuaTable if (lHasEnvironment) @@ -509,7 +515,7 @@ public static LambdaExpression ParseChunk(Lua runtime, LuaDebugLevel debug, bool // Get the name for the chunk and clean it from all unwanted chars string sChunkName = CreateNameFromFile(code.Current.Start.FileName); - if ((debug & LuaDebugLevel.RegisterMethods) == LuaDebugLevel.RegisterMethods) + if ((globalScope.EmitDebug & LuaDebugLevel.RegisterMethods) == LuaDebugLevel.RegisterMethods) sChunkName = Lua.RegisterUniqueName(sChunkName); // Create the block @@ -1950,7 +1956,7 @@ private static Expression GenerateForLoop(LoopScope loopScope, Token tStart, Lis Expression.Label(loopScope.ContinueLabel), // local tmp = f(s, var) - Expression.Assign(varTmp, InvokeExpression(loopScope.Runtime, tStart, varFunc, InvokeResult.LuaResult, + Expression.Assign(varTmp, InvokeExpression(loopScope, tStart, varFunc, InvokeResult.LuaResult, new Expression[] { varState, varVar }, true) ), @@ -2045,7 +2051,7 @@ private static Expression ParseFunctionAddChain(Scope scope, Token tStart, Expre assignee = expr; } else - assignee = MemberGetExpression(scope.Runtime, tStart, assignee, sMember, false); + assignee = MemberGetExpression(scope, tStart, assignee, sMember); return assignee; } // proc ParseFunctionAddChain diff --git a/NeoLua/Properties/AssemblyInfoGlobal.cs b/NeoLua/Properties/AssemblyInfoGlobal.cs index 64514b1..baa8f54 100644 --- a/NeoLua/Properties/AssemblyInfoGlobal.cs +++ b/NeoLua/Properties/AssemblyInfoGlobal.cs @@ -6,4 +6,4 @@ [assembly: AssemblyTrademark("")] [assembly: AssemblyVersion("5.3.0.0")] -[assembly: AssemblyFileVersion("0.9.11.0")] +[assembly: AssemblyFileVersion("0.9.12.0-beta")] diff --git a/NeoSpeed/Program.cs b/NeoSpeed/Program.cs index 56c2673..464f43a 100644 --- a/NeoSpeed/Program.cs +++ b/NeoSpeed/Program.cs @@ -10,7 +10,7 @@ namespace NeoSpeed { class Program { - private static Neo.IronLua.ILuaDebug debugNeoLua = Neo.IronLua.Lua.DefaultDebugEngine; + private static Neo.IronLua.ILuaDebug debugNeoLua = Neo.IronLua.Lua.DefaultDebugEngine.DebugEngine; static void Main(string[] args) { @@ -64,7 +64,7 @@ static void Main(string[] args) } Console.WriteLine(); Console.WriteLine("Precompiled (no cache clear, debug):"); - debugNeoLua = Neo.IronLua.Lua.DefaultDebugEngine; + debugNeoLua = Neo.IronLua.Lua.DefaultDebugEngine.DebugEngine; for (int i = 0; i < scripts.Length; i++) { string sScript1 = File.ReadAllText(String.Format(scripts[i], 1)); @@ -106,7 +106,7 @@ 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", debugNeoLua); + Neo.IronLua.LuaChunk chunk = lua.CompileChunk(sScript, "test", new Neo.IronLua.LuaCompileOptions() { DebugEngine = debugNeoLua }); Neo.IronLua.LuaGlobal g = lua.CreateEnvironment(); g["test"] = new Action(LuaTest); g["echo"] = new Func(LuaEcho);