public static LuryObject PrintLine(LuryObject value) { var text = value + "\n"; Console.Write(text); return(LuryString.GetObject(text)); }
public static LuryObject Print(LuryObject value) { var text = value.ToString(); Console.Write(text); return(LuryString.GetObject(text)); }
public void SetMember(string name, LuryObject obj) { if (IsFrozen) { throw new InvalidOperationException(); } if (members.ContainsKey(name)) { members[name] = obj; } else { members.Add(name, obj); } }
public static LuryContext CreateGlobalContext() { var context = new LuryContext(); #region Intrinsic Classes Action <string, string, IEnumerable <Tuple <string, MethodInfo> > > setFunctionMember = (t, n, f) => { var type = new LuryObject(t, null); foreach (var item in f) { type.SetMember(item.Item1, new LuryObject(LuryFunction.FullName, item.Item2, true)); } type.Freeze(); context[n] = type; context[type.LuryTypeName] = type; }; var intrinsicTypes = Assembly .GetExecutingAssembly() .GetTypes() .Where(t => t.IsClass && Attribute.GetCustomAttribute(t, typeof(IntrinsicClassAttribute)) != null); foreach (var type in intrinsicTypes) { var attr = type.GetCustomAttribute <IntrinsicClassAttribute>(); var methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public); var funcnames = methods .Select( method => new { method, attributes = method.GetCustomAttributes <IntrinsicAttribute>().Select(a => a.TargetFunction) }) .SelectMany(_ => _.attributes, (_, funcName) => Tuple.Create(funcName, _.method)).ToList(); if (funcnames.Count > 0) { setFunctionMember(attr.FullName, attr.TypeName, funcnames); } } #endregion #region BuiltIn Functions var builtInFunctions = Assembly .GetExecutingAssembly() .GetTypes() .Where(t => t.IsClass && Attribute.GetCustomAttribute(t, typeof(BuiltInClass)) != null); foreach (var type in builtInFunctions) { var attr = type.GetCustomAttribute <BuiltInClass>(); var methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public); var funcnames = methods .Select( method => new { method, attributes = method.GetCustomAttributes <BuiltInAttribute>().Select(a => a.FunctionName) }) .SelectMany(_ => _.attributes, (_, funcName) => Tuple.Create(funcName, _.method)).ToList(); foreach (var func in funcnames) { context[func.Item1] = LuryFunction.GetObject(func.Item2); } } #endregion return(context); }
public void SetMemberNoRecursion(string name, LuryObject value) { members.Add(name, value); }