diff --git a/Upsilon/BaseTypes/ScriptFunction/ScriptRuntimeFunction.cs b/Upsilon/BaseTypes/ScriptFunction/ScriptRuntimeFunction.cs index 1132449..bd18d2b 100644 --- a/Upsilon/BaseTypes/ScriptFunction/ScriptRuntimeFunction.cs +++ b/Upsilon/BaseTypes/ScriptFunction/ScriptRuntimeFunction.cs @@ -93,6 +93,36 @@ namespace Upsilon.BaseTypes.ScriptFunction return null; } + public void AddOption(ScriptRuntimeFunctionOption newOption) + { + var variables = newOption.Parameters; + for (var i = 0; i < Options.Count; i++) + { + var option = Options[i]; + if (option.Parameters.Length != variables.Length) + continue; + bool isCompatible = true; + for (var index = 0; index < variables.Length; index++) + { + var callingVariable = variables[index]; + var optionVariable = option.Parameters[index]; + if (callingVariable.Type == BaseTypes.Type.Unknown || callingVariable.Type == BaseTypes.Type.Nil || + optionVariable.Type == BaseTypes.Type.Unknown) + continue; + if (callingVariable.Type != optionVariable.Type) + { + isCompatible = false; + break; + } + } + if (!isCompatible) + continue; + Options[i] = newOption; + break; + } + Options.Add(newOption); + } + public class ScriptRuntimeFunctionOption : IScopeOwner { diff --git a/Upsilon/Evaluator/Evaluator.cs b/Upsilon/Evaluator/Evaluator.cs index efa004a..1fbb9fd 100644 --- a/Upsilon/Evaluator/Evaluator.cs +++ b/Upsilon/Evaluator/Evaluator.cs @@ -501,7 +501,7 @@ namespace Upsilon.Evaluator { if (Scope.Variables.TryGetValue(e.Variable.Name, out var f) && f is ScriptRuntimeFunction scriptRuntimeFunction) { - scriptRuntimeFunction.Options.AddRange(func.Options); + scriptRuntimeFunction.AddOption(func.Options[0]); } else { @@ -512,7 +512,7 @@ namespace Upsilon.Evaluator { if (Scope.TryGet(e.Variable, out var f) && f is ScriptRuntimeFunction scriptRuntimeFunction) { - scriptRuntimeFunction.Options.AddRange(func.Options); + scriptRuntimeFunction.AddOption(func.Options[0]); } else {