Browse Source

Update README.md

Sébastien Ros 11 years ago
parent
commit
e621a7cc32
1 changed files with 21 additions and 21 deletions
  1. 21 21
      README.md

+ 21 - 21
README.md

@@ -15,7 +15,7 @@ It's available on nuget at https://www.nuget.org/packages/Jint
 
 
 This example defines a new value named `log` pointing to `Console.WriteLine`, then executes 
 This example defines a new value named `log` pointing to `Console.WriteLine`, then executes 
 a script calling `log('Hello World!')`. 
 a script calling `log('Hello World!')`. 
-
+```csharp
     var engine = new Engine()
     var engine = new Engine()
         .SetValue("log", new Action<object>(Console.WriteLine))
         .SetValue("log", new Action<object>(Console.WriteLine))
         ;
         ;
@@ -27,18 +27,18 @@ a script calling `log('Hello World!')`.
       
       
       hello();
       hello();
     ");
     ");
-
+```
 Here, the variable `x` is set to `3` and `x * x` is executed in JavaScript. The result is returned to .NET directly, in this case as a `double` value `9`. 
 Here, the variable `x` is set to `3` and `x * x` is executed in JavaScript. The result is returned to .NET directly, in this case as a `double` value `9`. 
-
+```csharp
     var square = new Engine()
     var square = new Engine()
         .SetValue("x", 3) // define a new variable
         .SetValue("x", 3) // define a new variable
         .Execute("x * x") // execute a statement
         .Execute("x * x") // execute a statement
         .GetCompletionValue() // get the latest statement completion value
         .GetCompletionValue() // get the latest statement completion value
         .ToObject() // converts the value to .NET
         .ToObject() // converts the value to .NET
         ;
         ;
-
+```
 You can also directly pass POCOs or anonymous objects and use them from JavaScript. In this example for instance a new `Person` instance is manipulated from JavaScript. 
 You can also directly pass POCOs or anonymous objects and use them from JavaScript. In this example for instance a new `Person` instance is manipulated from JavaScript. 
-
+```csharp
     var p = new Person {
     var p = new Person {
         Name = "Mickey Mouse"
         Name = "Mickey Mouse"
     };
     };
@@ -47,9 +47,9 @@ You can also directly pass POCOs or anonymous objects and use them from JavaScri
         .SetValue("p", p)
         .SetValue("p", p)
         .Execute("p.Name === 'Mickey Mouse')
         .Execute("p.Name === 'Mickey Mouse')
         ;
         ;
-
+```
 If you need to pass a JavaScript callback to the CLR, then it will be converted to a `Delegate`. You can also use it as a parameter of a CLR method from JavaScript.
 If you need to pass a JavaScript callback to the CLR, then it will be converted to a `Delegate`. You can also use it as a parameter of a CLR method from JavaScript.
-
+```csharp
     var function = new Engine()
     var function = new Engine()
         .Execute("function add(a, b) { return this + a + b; }");
         .Execute("function add(a, b) { return this + a + b; }");
         .GetGlobalValue("add")
         .GetGlobalValue("add")
@@ -59,37 +59,37 @@ If you need to pass a JavaScript callback to the CLR, then it will be converted
         new JsValue("foo") /* thisArg */, 
         new JsValue("foo") /* thisArg */, 
         new JsValue[] { 1, "bar" } /* arguments */,
         new JsValue[] { 1, "bar" } /* arguments */,
         ); // "foo1bar"
         ); // "foo1bar"
-
+```
 ## Accessing .NET assemblies and classes
 ## Accessing .NET assemblies and classes
 
 
 You can allow an engine to access any .NET class by configuring the engine instance like this:
 You can allow an engine to access any .NET class by configuring the engine instance like this:
-
+```csharp
     var engine = new Engine(cfg => cfg.AllowClr())
     var engine = new Engine(cfg => cfg.AllowClr())
-
+```
 Then you have access to the `System` namespace as a global value. Here is how it's used in the context on the command line utility:
 Then you have access to the `System` namespace as a global value. Here is how it's used in the context on the command line utility:
-
+```javascript
     jint> var file = new System.IO.File('log.txt');
     jint> var file = new System.IO.File('log.txt');
     jint> file.WriteLine('Hello World !');
     jint> file.WriteLine('Hello World !');
     jint> file.Dispose();
     jint> file.Dispose();
-
+```
 And even create shortcuts to commong .NET methods
 And even create shortcuts to commong .NET methods
-
+```javascript
     jint> var log = System.Console.WriteLine;
     jint> var log = System.Console.WriteLine;
     jint> log('Hello World !');
     jint> log('Hello World !');
     => "Hello World !"
     => "Hello World !"
-
+```
 When allowing the CLR, you can optionnally pass custom assemblies to load types from. 
 When allowing the CLR, you can optionnally pass custom assemblies to load types from. 
-
+```csharp
     var engine = new Engine(cfg => cfg
     var engine = new Engine(cfg => cfg
         .AllowClr(typeof(Bar).Assembly)
         .AllowClr(typeof(Bar).Assembly)
     )
     )
-
+```
 and then to assign local namespaces the same way `System` does it for you, use `importNamespace`
 and then to assign local namespaces the same way `System` does it for you, use `importNamespace`
-
-    var Foo = importNamespace('Foo');
-    var bar = new Foo.Bar();
-    log(bar.ToString());
-    
+```javascript
+    jint> var Foo = importNamespace('Foo');
+    jint> var bar = new Foo.Bar();
+    jint> log(bar.ToString());
+```    
 ## Implemented features:
 ## Implemented features:
 
 
 - ECMAScript 5.1 test suite (http://test262.ecmascript.org/) 
 - ECMAScript 5.1 test suite (http://test262.ecmascript.org/)