diff --git a/Upsilon/BaseTypes/ScriptFunction/ScriptGenericFunction.cs b/Upsilon/BaseTypes/ScriptFunction/ScriptGenericFunction.cs deleted file mode 100644 index 8266473..0000000 --- a/Upsilon/BaseTypes/ScriptFunction/ScriptGenericFunction.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using Upsilon.Evaluator; - -namespace Upsilon.BaseTypes.ScriptFunction -{ - public class ScriptGenericFunction : ScriptFunction - { - public ScriptGenericFunction(Func> function) - { - Function = function; - } - - public ScriptGenericFunction(object o) - { - var type = o.GetType(); - var generics = type.GetGenericArguments(); - Function.GetMethodInfo(); - } - - public Func> Function { get; } - - public override ScriptType Run(Diagnostics diagnostics, ScriptType[] variables, Script script, - EvaluationScope scope) - { - return Function.Invoke(variables.Select(x => x.ToCSharpObject())).ToScriptType(); - } - } -} \ No newline at end of file diff --git a/Upsilon/BaseTypes/TypeConversion.cs b/Upsilon/BaseTypes/TypeConversion.cs index 76af299..9944e5d 100644 --- a/Upsilon/BaseTypes/TypeConversion.cs +++ b/Upsilon/BaseTypes/TypeConversion.cs @@ -50,7 +50,15 @@ namespace Upsilon.BaseTypes if (generic.FullName != null && generic.FullName.Contains("System.Func")) { var function = (Delegate)o; - var method = new UserDataMethod(function.GetMethodInfo()); + var method = new UserDataMethod(function.GetMethodInfo()); + return new ScriptMethodInfoFunction(method, null, false, + false, false); + } + + if (generic.FullName != null && generic.FullName.Contains("System.Action")) + { + var function = (Delegate)o; + var method = new UserDataMethod(function.GetMethodInfo()); return new ScriptMethodInfoFunction(method, null, false, false, false); } diff --git a/Upsilon/BaseTypes/UserData/UserDataTypeHandler.cs b/Upsilon/BaseTypes/UserData/UserDataTypeHandler.cs index d86a98d..45cfbc1 100644 --- a/Upsilon/BaseTypes/UserData/UserDataTypeHandler.cs +++ b/Upsilon/BaseTypes/UserData/UserDataTypeHandler.cs @@ -6,12 +6,12 @@ namespace Upsilon.BaseTypes.UserData { public static class UserDataTypeHandler { - private static readonly Dictionary _types = new Dictionary(); + private static readonly Dictionary Types = new Dictionary(); public static void LoadType(System.Type t) { var info = new UserDataType(t); - _types.Add(t, info); + Types.Add(t, info); UserDataBoundTypeDefinition boundType; if (t.IsEnum) { @@ -31,7 +31,7 @@ namespace Upsilon.BaseTypes.UserData internal static UserDataType GetTypeInfo(System.Type t) { - return _types[t]; + return Types[t]; } } } \ No newline at end of file diff --git a/Upsilon/StandardLibraries/StaticScope.cs b/Upsilon/StandardLibraries/StaticScope.cs index 50c66dc..e74aa90 100644 --- a/Upsilon/StandardLibraries/StaticScope.cs +++ b/Upsilon/StandardLibraries/StaticScope.cs @@ -87,10 +87,14 @@ namespace Upsilon.StandardLibraries if (type.IsGenericType) { var generic = type.GetGenericTypeDefinition(); - if (generic.FullName != null && generic.FullName.Contains("System.Func")) + if (generic.FullName != null && generic.FullName.StartsWith("System.Func")) { varSymbol = BuildFunctionVariableSymbol(name, type); } + else if (generic.FullName != null && generic.FullName.StartsWith("System.Action")) + { + varSymbol = BuildActionVariableSymbol(name, type); + } } if (varSymbol == null) throw new Exception("Unknown type: " + type); @@ -103,7 +107,7 @@ namespace Upsilon.StandardLibraries private static VariableSymbol BuildFunctionVariableSymbol(string name, System.Type type) { var genericParameters = type.GetGenericArguments(); - var parameters = new List(); + var parameters = new List(); for (var i = 0; i < genericParameters.Length - 1; i++) { var t = genericParameters[i].GetScriptType(); @@ -114,6 +118,18 @@ namespace Upsilon.StandardLibraries return new InternalFunctionVariableSymbol(name, true, result, parameters.ToArray()); } + private static VariableSymbol BuildActionVariableSymbol(string name, System.Type type) + { + var genericParameters = type.GetGenericArguments(); + var parameters = new List(); + for (var i = 0; i < genericParameters.Length; i++) + { + var t = genericParameters[i].GetScriptType(); + parameters.Add(new InternalFunctionVariableSymbol.InternalFunctionParameter(t, false)); + } + return new InternalFunctionVariableSymbol(name, true, Type.Nil, parameters.ToArray()); + } + private static Type DeriveValidTypes(System.Type type) { if (type == typeof(ScriptString))