Created
August 13, 2013 12:03
-
-
Save eralpkaraduman/6220436 to your computer and use it in GitHub Desktop.
implementing ironJS javascript DLR runtime on mono using c#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using IronJS; | |
using IronJS.Hosting; | |
using IronJS.Compiler; | |
using System.Collections; | |
namespace ironJSTest | |
{ | |
class MainClass | |
{ | |
static ArrayList endpointsList = new ArrayList(); | |
public static void Main (string[] args) | |
{ | |
var context = new IronJS.Hosting.CSharp.Context (); | |
string path = System.IO.Path.Combine(System.Environment.CurrentDirectory,@"test.js"); | |
context.ExecuteFile (path); | |
var ends = context.Globals.GetT<FunctionObject> ("endPoints"); | |
ArrayObject arrayObject = ends.Call (context.Globals).Unbox<ArrayObject>(); | |
for (int i = 0; i < arrayObject.Length; i++) { | |
String endpointName = arrayObject.Get (i).String; | |
Console.WriteLine (i+") "+endpointName); | |
endpointsList.Add (endpointName); | |
} | |
while (true) { | |
string line = Console.ReadLine (); | |
if (line.Length > 0) { | |
bool has = endpointsList.Contains (line); | |
if (has) { | |
var value = context.Execute (line + "();"); | |
Console.WriteLine (value); | |
} else { | |
Console.WriteLine ("invalid"); | |
} | |
} | |
} | |
} | |
public static void Print(BoxedValue value) | |
{ | |
Console.WriteLine(value.Array); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function endPoints(){ | |
return [ | |
"getScore", | |
"getUserName" | |
]; | |
} | |
function getScore(){ | |
return 170+5; | |
} | |
function getUserName(){ | |
return "eralp"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment