// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; using Microsoft.JScript; // Note: VSA is obsolete since .NET 2.0 - the recommended replacement is to compile using JScript compiler namespace M2M { public class Program { public static void TestJS(String source) { Console.WriteLine(source); #pragma warning disable 618 Microsoft.JScript.Vsa.VsaEngine eng = Microsoft.JScript.Vsa.VsaEngine.CreateEngine(); eng.SetOption("print", true); string prefix = "var n = 3;\r\nvar s = 'Hi';\r\n"; string res = (string)Eval.JScriptEvaluate(prefix + source, eng); Console.WriteLine(res); #pragma warning restore 618 } public static void Main(String[] args) { TestJS("for(var i = 0; i < n; i++) {\r\n" + " print(\"JScript says: \" + s);\r\n" + "}\r\n" + "\"OK\""); } } }