예제 #1
0
        private static dynamic InstanceEval(object self, string eval, NovaScope scope)
        {
            if (!(self is NovaInstance instance))
            {
                return(null);
            }

            var        xexpression = string.Format("{0};", eval);
            var        res         = NovaParser.Parse(xexpression);
            Expression block;

            if (res != null)
            {
                scope["self"] = scope["super"] = instance;
                scope["<nova_context_invokemember>"] = true;
                string selfName;
                var    selfScope = scope.SearchForObject(instance, out selfName);
                if (selfScope != null && selfName != null)
                {
                    scope["<nova_context_selfscope>"] = selfScope;
                    scope["<nova_context_selfname>"]  = selfName;
                }
                block = NovaExpression.NovaBlock(res);
                // We want eval'd expressions to execute in the current scope, not its own child scopes.  This ensures assignment evals work properly.
                ((BlockExpression)block).Scope = scope;
                ((BlockExpression)block).SetChildrenScopes(scope);
            }
            else
            {
                return(null);
            }
            var val = CompilerServices.CreateLambdaForExpression(block)();

            return(val);
        }
예제 #2
0
        private static dynamic Eval(string eval, NovaScope scope)
        {
            var xexpression = string.Format("{0};", eval);

            var        res = NovaParser.Parse(xexpression);
            Expression block;

            if (res != null)
            {
                block = NovaExpression.NovaBlock(res);
                // We want eval'd expressions to execute in the current scope, not its own child scopes.  This ensures assignment evals work properly.
                ((BlockExpression)block).Scope = scope;
                ((BlockExpression)block).SetChildrenScopes(scope);
            }
            else
            {
                return(null);
            }
            var val = CompilerServices.CreateLambdaForExpression(block)();

            return(val);
        }