static void Main(string[] args) { ScriptRuntime runtime = IronRuby.CreateRuntime(); ScriptEngine engine = IronRuby.GetEngine(runtime); ScriptScope scope = engine.CreateScope(); StringAdder adder = new StringAdder(); scope.Execute("def self.string_added(val = ''); puts \"The string \\\"#{val}\\\" has been added.\"; end;"); StringAdder.OnStringAddedDelegate functionPointer = scope.GetVariable<StringAdder.OnStringAddedDelegate>("string_added"); adder.OnStringAdded += functionPointer; Console.WriteLine("Initialisation complete. About to add some strings.\r\n"); adder.Add("IronRuby"); adder.Add("IronPython"); adder.Add("VBx"); adder.Add("Managed JavaScript"); adder.Add("IronLisp"); adder.Add("IronScheme"); adder.Add("Nua"); Console.WriteLine("\r\nSome DLR languages: " + adder); // Outputs the following: // // Initialisation complete. About to add some strings. // // The string "IronRuby" has been added. // The string "IronPython" has been added. // The string "VBx" has been added. // The string "Managed JavaScript" has been added. // The string "IronLisp" has been added. // The string "IronScheme" has been added. // The string "Nua" has been added. // // Some DLR languages: IronRuby, IronPython, VBx, Managed JavaScript, IronLisp, IronScheme, Nua }
static void Main(string[] args) { //TODO: update when hosting API changes // ScriptScope scope = engine.CreateScope(); // scope.SetVariable("txt", "IronRuby is awesome!"); // scope.Execute("def self.upper; txt.to_s.upcase; end;"); // // string result = scope.GetVariable<Function<string>>("upper")(); // Console.WriteLine("The result is: " + result); // Console.WriteLine(""); ScriptRuntime runtime = IronRuby.CreateRuntime(); ScriptEngine engine = IronRuby.GetEngine(runtime); ScriptScope scope = engine.CreateScope(); StringAdder adder = new StringAdder(); scope.Execute("def self.string_added(val = ''); puts \"The string \\\"#{val}\\\" has been added.\"; end;"); StringAdder.OnStringAddedDelegate functionPointer = scope.GetVariable<StringAdder.OnStringAddedDelegate>("string_added"); adder.OnStringAdded += functionPointer; Console.WriteLine("Initialisation complete. About to add some strings.\r\n"); adder.Add("IronRuby"); adder.Add("IronPython"); adder.Add("VBx"); adder.Add("Managed JavaScript"); adder.Add("IronLisp"); adder.Add("IronScheme"); adder.Add("Nua"); Console.WriteLine("\r\nSome DLR languages: " + adder); Console.WriteLine("\r\nPress any key to close..."); Console.ReadKey(); }