//TODO replace with a generic method private static void RegisterNetFunction(FunctionRegistration method) { var first = method.NetAttributes.First(); string defaultName = first.Name; var firstParameterType = method.Method.GetParameters()[0].ParameterType; NetFunction netFunction; if (typeof(IValue).IsAssignableFrom(firstParameterType)) { var deleg = method.Method.CreateDelegate <Func <IValue, Scope, IValue> >(); netFunction = new NetFunction(deleg, defaultName, first.Line, GetFileName(first)); } else { var deleg = method.Method.CreateDelegate <Func <List <IValue>, Scope, IValue> >(); netFunction = new NetFunction(deleg, defaultName, first.Line, GetFileName(first)); } foreach (var globalname in method.NetAttributes) { Scope[globalname.Name] = netFunction; } }
internal static IValue ImportFunction(ListNode list, Scope scope) { int children = list.Children.Count - 1; if (children < 1) { throw new ArgumentException("Too few parameters"); } var args = list.Children.Skip(1).ToArray(); var nameIdentifier = (IdentifierNode)args[0]; string name = nameIdentifier.Name; var methodIdentifier = (IdentifierNode)args[1]; string methodName = methodIdentifier.Name; var argTypes = new Type[children > 2 ? children - 2 : 0]; int startIndex = 2; for (int i = startIndex; i < children; i++) { var typeIdentifier = (IdentifierNode)args[i]; var types = AllTypes[typeIdentifier.Name]; var type = types.First(); argTypes[i - startIndex] = type; } var method = FindMethodWithTypes(scope, methodName, argTypes); scope[name] = Value.Nil; var function = new NetFunction(CreateNetFunction(method), methodName); scope[name] = function; return(function); }