Skip to content

Instantly share code, notes, and snippets.

@eralpkaraduman
Created August 13, 2013 12:03
Show Gist options
  • Save eralpkaraduman/6220436 to your computer and use it in GitHub Desktop.
Save eralpkaraduman/6220436 to your computer and use it in GitHub Desktop.
implementing ironJS javascript DLR runtime on mono using c#
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);
}
}
}
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