Beispiel #1
0
        public static DekiScriptMap ValidateToMap(DekiScriptParameter[] parameters, DekiScriptList args) {
            DekiScriptMap result = new DekiScriptMap();

            // check passed in arguments
            int i = 0;
            var count = Math.Min(args.Value.Count, parameters.Length);
            for(; i < count; ++i) {
                var value = args[i];
                if(value.IsNil) {
                    if((parameters[i].ScriptType != DekiScriptType.ANY) && !parameters[i].Optional) {
                        throw new ArgumentException(string.Format("missing value for parameter '{0}' (index {1})", parameters[i].Name, i));
                    }

                    // set default value for this parameter
                    result.Add(parameters[i].Name, parameters[i].Default);
                } else {
                    result.Add(parameters[i].Name, parameters[i].Convert(value));
                }
            }

            // check that missing arguments are optional
            for(; i < parameters.Length; ++i) {
                if((parameters[i].ScriptType != DekiScriptType.ANY) && !parameters[i].Optional) {
                    throw new ArgumentException(string.Format("missing value for parameter '{0}' (index {1})", parameters[i].Name, i));
                }
                result.Add(parameters[i].Name, parameters[i].Default);
            }
            return result;
        }
 //--- Constructors ---
 public DekiScriptScriptFunctionInvocationTarget(DreamAccess access, DekiScriptParameter[] parameters, DekiScriptExpression expr, DekiScriptEnv env, DekiScriptType returnType) {
     if(parameters == null) {
         throw new ArgumentNullException("parameters");
     }
     if(expr == null) {
         throw new ArgumentNullException("expr");
     }
     this.Access = access;
     this.Parameters = parameters;
     this.Expression = expr;
     _env = env;
     _returnType = returnType;
 }
Beispiel #3
0
 //--- Constructors ---
 public DekiScriptInvalidParameterCastException(Location location, DekiScriptParameter parameter, DekiScriptType sourceType) : base(location, MakeMessage(parameter, sourceType)) {
     this.Parameter = parameter;
     this.SourceType = sourceType;
 }
Beispiel #4
0
 //--- Class Methods ---
 protected static string MakeMessage(DekiScriptParameter parameter, DekiScriptType sourceType) {
     return string.Format("parameter '{2}' could not convert from '{0}' to '{1}'", sourceType.ToString().ToLowerInvariant(), parameter.ScriptType.ToString().ToLowerInvariant(), parameter.Name);
 }
Beispiel #5
0
 //--- Constructors ---
 public DekiScriptInvalidParameterCastException(Location location, DekiScriptParameter parameter, DekiScriptType sourceType) : base(location, MakeMessage(parameter, sourceType))
 {
     this.Parameter  = parameter;
     this.SourceType = sourceType;
 }
Beispiel #6
0
 //--- Class Methods ---
 protected static string MakeMessage(DekiScriptParameter parameter, DekiScriptType sourceType)
 {
     return(string.Format("parameter '{2}' could not convert from '{0}' to '{1}'", sourceType.ToString().ToLowerInvariant(), parameter.ScriptType.ToString().ToLowerInvariant(), parameter.Name));
 }
Beispiel #7
0
        public static DekiScriptList ValidateToList(DekiScriptParameter[] parameters, DekiScriptMap args) {
            DekiScriptList result = new DekiScriptList();

            // check passed in arguments
            for(int i = 0; i < parameters.Length; ++i) {
                var value = args[parameters[i].Name];
                if(value.IsNil) {
                    if((parameters[i].ScriptType != DekiScriptType.ANY) && !parameters[i].Optional) {
                        throw new ArgumentException(string.Format("missing value for parameter '{0}' (index {1})", parameters[i].Name, i));
                    }

                    // set default value for this parameter
                    result.Add(parameters[i].Default);
                } else {
                    result.Add(parameters[i].Convert(value));
                }
            }
            return result;
        }