/// <summary> /// Processes an HTTP Web request using the LSharp runtime. /// </summary> /// <param name="context"></param> public void ProcessRequest(HttpContext context) { // Create a new environment with access to the HttpContext Environment environment = new Environment(); environment.Assign(Symbol.FromName("*context*"), context); environment.Assign(Symbol.FromName("*response*"), context.Response); environment.Assign(Symbol.FromName("*request*"), context.Request); environment.Assign(Symbol.FromName("*application*"), context.Application); environment.Assign(Symbol.FromName("*session*"), context.Session); // The url requested maps to a physical file which contains the // L Sharp code to be interpreted. string filename = context.Request.PhysicalPath; filename = filename.Replace("\\", "\\\\"); // Load the code in the newly created context string expression = string.Format("(load \"{0}\")", filename); try { Runtime.EvalString(expression, environment); } catch (Exception e) { context.Response.Write("<h1>Error Loading L# File " + filename + "</h1><br />"); context.Response.Write("<br /> <font color='red'>"); context.Response.Write(e.ToString().Replace("\n", "<br />")); context.Response.Write("</font>"); } }
public static Object Setq(Cons args, Environment environment) { object v = null; while (args != null) { Symbol s = (Symbol)args.First(); v = Runtime.Eval(args.Second(), environment); environment.Assign(s, v); args = (Cons)args.Cddr(); } return(v); }
/// <summary> /// Creates the Library entries for L# /// </summary> /// <param name="environment"></param> public static void Register(Environment environment) { environment.Assign(Symbol.FromName("gui-inspect"), new Function(GuiInspect)); environment.Assign(Symbol.FromName("play-sound"), new Function(PlaySound)); }
/// <summary> /// Creates the Library entries for L# /// </summary> /// <param name="environment"></param> public Container(Environment environment) { environment.Assign(Symbol.FromName("gui-inspect"), new Function(GuiInspect)); environment.Assign(Symbol.FromName("play-sound"), new Function(PlaySound)); }
/// <summary> /// (= { symbol value}*) /// Setq (Set Quote) is the variable assignment operator. /// Sets each variable symbol to value in the current environment. /// The abbreviation = is more commonly used in L Sharp. /// </summary> /// <param name="args"></param> /// <param name="environment"></param> /// <returns></returns> public static Object Setq(Cons args, Environment environment) { object v = null; while (args != null) { Symbol s = (Symbol)args.First(); v = Runtime.Eval(args.Second(),environment); environment.Assign(s,v); args = (Cons)args.Cddr(); } return v; }
/// <summary> /// (++ symbol) /// Adds one to the variable represented by symbol. A shorthand for /// (= symbol (+ symbol 1)) /// </summary> /// <param name="args"></param> /// <param name="environment"></param> /// <returns></returns> public static Object Increment(Cons args, Environment environment) { object o = Runtime.Eval(args.First(), environment); object result; if (o is Double) result = (Double)o + 1; else result = (Int32)o + 1; return environment.Assign((Symbol) args.First(), result); }