private static void AddParameters(IndicatorSource indicatorSource, FunctionCall createIndicatorCall)
        {
            foreach (var param in indicatorSource.Parameters)
            {
                switch (param)
                {
                case BoolParameter boolParam:
                    createIndicatorCall.AddParameter(boolParam.Value ? "true" : "false");
                    break;

                case IntParameter intParam:
                    createIndicatorCall.AddParameter(intParam.Value.ToString());
                    break;

                case StringParameter stringParam:
                    createIndicatorCall.AddParameter($"\"{stringParam.Value}\"");
                    break;

                case ExternalParameter externalParam:
                    createIndicatorCall.AddParameter($"instance.parameters.{externalParam.Value}");
                    break;

                case DoubleParameter doubleParam:
                    createIndicatorCall.AddParameter(doubleParam.Value.ToLuaDoubleString());
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
        }
示例#2
0
        private IPrimitive FormatCrossMethodCall(MetaFormulaItem arg1, MetaFormulaItem arg2, string methodName)
        {
            var methodCall = new FunctionCall(methodName)
                             .AddParameter(FormatStreamOrValue(arg1))
                             .AddParameter(FormatStreamOrValue(arg2));

            if (arg1.PeriodShiftSource != null)
            {
                methodCall.AddParameter(FormatPeriod(arg1));
            }
            else
            {
                IPrimitive period = FormatNowPeriod(arg1);
                methodCall.AddParameter(period)
                .AddCondition(_factory.MakeIsNotNull(period));
            }
            if (arg2.ValueType == FormulaItemType.Stream)
            {
                if (arg2.PeriodShiftSource != null)
                {
                    methodCall.AddParameter(FormatPeriod(arg2));
                }
                else
                {
                    IPrimitive period = FormatNowPeriod(arg2);
                    methodCall.AddParameter(period)
                    .AddCondition(_factory.MakeIsNotNull(period));
                }
            }
            return(_factory.MakeConst(AddRangeChecks(arg1, arg2, methodCall)));
        }