예제 #1
0
            }             // func GetTargetDynamicCall

            private DynamicMetaObject GetTargetDynamicCall(CallSiteBinder binder, Type typeReturn, DynamicMetaObject arg)
            {
                return(GetTargetDynamicCall(binder, typeReturn,
                                            new Expression[]
                {
                    GetFirstResultExpression(),
                    LuaEmit.Convert(Lua.GetRuntime(binder), arg.Expression, arg.LimitType, typeof(object), false)
                }
                                            ));
            }             // func GetTargetDynamicCall
예제 #2
0
            } // ctor

            public override DynamicMetaObject FallbackConvert(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
            {
                if (!target.HasValue)
                {
                    return(Defer(target));
                }

                Expression          expr         = target.Expression;
                BindingRestrictions restrictions = null;

                if (target.Value == null) // get the default value
                {
                    restrictions = target.Restrictions.Merge(BindingRestrictions.GetInstanceRestriction(target.Expression, null));
                    if (this.Type == typeof(LuaResult)) // replace null with empty LuaResult
                    {
                        expr = Expression.Property(null, Lua.ResultEmptyPropertyInfo);
                    }
                    else if (this.Type == typeof(string)) // replace null with empty String
                    {
                        expr = Expression.Field(null, Lua.StringEmptyFieldInfo);
                    }
                    else
                    {
                        expr = Expression.Default(this.Type);
                    }
                }
                else // convert the value
                {
                    restrictions = target.Restrictions.Merge(BindingRestrictions.GetTypeRestriction(target.Expression, target.LimitType));
                    try
                    {
                        expr = LuaEmit.Convert(lua, target.Expression, target.LimitType, this.Type, false); // no dynamic allowed
                    }
                    catch (LuaEmitException e)
                    {
                        if (errorSuggestion != null)
                        {
                            return(errorSuggestion);
                        }
                        expr = ThrowExpression(e.Message, this.Type);
                    }
                }

                return(new DynamicMetaObject(expr, restrictions));
            } // func FallbackConvert
예제 #3
0
        }         // func RestrictAccess

        /// <summary>Most core method, that gets called to sandbox a value.</summary>
        /// <param name="expression">Expression, that should be sandboxed.</param>
        /// <param name="instance">Optional: Instance, that was called to get the expression.</param>
        /// <param name="sMember">Optional: Name of the member that was used to resolve the expression.</param>
        /// <returns>Sandboxed expression</returns>
        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
예제 #4
0
        }         // func BinaryOperationExpression

        private static Expression ConcatOperationExpression(Lua runtime, Token tStart, Expression[] args)
        {
            if (Array.Exists(args, c => LuaEmit.IsDynamicType(c.Type)))             // we have a dynamic type in the list -> to the concat on runtime
            {
                return(SafeExpression(() => Expression.Call(Lua.ConcatStringMethodInfo, Expression.NewArrayInit(typeof(object),
                                                                                                                from e in args select ConvertObjectExpression(runtime, tStart, e, true))), tStart));
            }
            else
            {
                return(SafeExpression(() => Expression.Call(Lua.StringConcatMethodInfo, Expression.NewArrayInit(typeof(string),
                                                                                                                from e in args select LuaEmit.Convert(runtime, e, e.Type, typeof(string), true))), tStart));
            }
        }         // func ConcatOperationExpression
예제 #5
0
        }         // func ConvertObjectExpression

        private static Expression ConvertExpression(Lua runtime, Token tStart, Expression expr, Type toType)
        {
            return(SafeExpression(() => LuaEmit.Convert(runtime, expr, expr.Type, toType, true), tStart));
        }         // func ConvertExpression