예제 #1
0
            public override DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder)
            {
                if (binder.Operation != ExprType.Negate)
                {
                    throw new Exception(); // TODO
                }
                var expression = MetamethodFallbacks.UnaryMinus(null, this);

                return(new DynamicMetaObject(expression, RuntimeHelpers.MergeTypeRestrictions(this)));
            }
예제 #2
0
            public override DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg)
            {
                if (!LuaBinaryOperationBinder.BinaryExprTypes.ContainsKey(binder.Operation))
                {
                    throw new Exception(); // TODO
                }
                var expression = MetamethodFallbacks.BinaryOp(null, binder.Operation, this, arg);

                return(new DynamicMetaObject(expression, RuntimeHelpers.MergeTypeRestrictions(this)));
            }
예제 #3
0
            public override DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes)
            {
                var valueVar = Expr.Variable(typeof(object));

                var getValue = Expr.Call(
                    Expr.Convert(Expression, typeof(LuaTable)),
                    MemberInfos.LuaTableGetValue,
                    Expr.Convert(indexes[0].Expression, typeof(object)));
                var valueAssign = Expr.Assign(valueVar, getValue);

                var expression = Expr.Block(
                    valueVar,
                    Expr.Condition(
                        Expr.Equal(valueVar, Expr.Constant(null)),
                        MetamethodFallbacks.Index(null, this, indexes),
                        valueVar));

                return(new DynamicMetaObject(expression, RuntimeHelpers.MergeTypeRestrictions(this)));
            }
예제 #4
0
            public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value)
            {
                var getValue = Expr.Call(
                    Expr.Convert(Expression, typeof(LuaTable)),
                    MemberInfos.LuaTableGetValue,
                    Expr.Convert(indexes[0].Expression, typeof(object)));

                var setValue = Expr.Call(
                    Expr.Convert(Expression, typeof(LuaTable)),
                    MemberInfos.LuaTableSetValue,
                    Expr.Convert(indexes[0].Expression, typeof(object)),
                    Expr.Convert(value.Expression, typeof(object)));

                var expression = Expr.Condition(
                    Expr.Equal(getValue, Expr.Constant(null)),
                    MetamethodFallbacks.NewIndex(null, this, indexes, value),
                    setValue);

                return(new DynamicMetaObject(expression, RuntimeHelpers.MergeTypeRestrictions(this)));
            }
예제 #5
0
            public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
            {
                var expression = MetamethodFallbacks.Call(null, this, args);

                return(new DynamicMetaObject(expression, RuntimeHelpers.MergeTypeRestrictions(this)));
            }