Override function if function with exact same parameters was already defined
This commit is contained in:
parent
9aea17c445
commit
1955515f22
|
@ -93,6 +93,36 @@ namespace Upsilon.BaseTypes.ScriptFunction
|
||||||
return null;
|
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
|
public class ScriptRuntimeFunctionOption : IScopeOwner
|
||||||
{
|
{
|
||||||
|
|
|
@ -501,7 +501,7 @@ namespace Upsilon.Evaluator
|
||||||
{
|
{
|
||||||
if (Scope.Variables.TryGetValue(e.Variable.Name, out var f) && f is ScriptRuntimeFunction scriptRuntimeFunction)
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@ -512,7 +512,7 @@ namespace Upsilon.Evaluator
|
||||||
{
|
{
|
||||||
if (Scope.TryGet(e.Variable, out var f) && f is ScriptRuntimeFunction scriptRuntimeFunction)
|
if (Scope.TryGet(e.Variable, out var f) && f is ScriptRuntimeFunction scriptRuntimeFunction)
|
||||||
{
|
{
|
||||||
scriptRuntimeFunction.Options.AddRange(func.Options);
|
scriptRuntimeFunction.AddOption(func.Options[0]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue