[Ironruby-core] Busy Day with IronRuby
Ivan Porto Carrero
ivan at flanders.co.nz
Sun Jan 27 18:26:29 EST 2008
hello_world.rb only contains: puts "Hello, World!!!"
hth
Ivan
On Jan 28, 2008 12:23 PM, Ivan Porto Carrero <ivan at flanders.co.nz> wrote:
> Hi Greg,
>
> This is what i used at some point, that should still work atm.
>
> class Program
> {
> static void Main(string[] args)
> {
> //TODO: review this when the hosting api changes.
> IScriptEnvironment runtime = ScriptEnvironment.GetEnvironment
> ();
>
> Console.WriteLine("Executing from file:");
> runtime.ExecuteFile("..\\..\\hello_world.rb");
>
> IScriptEngine engine = IronRuby.GetEngine(runtime);
> IScriptScope scope = engine.CreateScope();
>
> List<string> strings = new List<string>();
> strings.Add("Hello, ");
> strings.Add("World!!!");
> IronRuby.GetExecutionContext(runtime).GlobalVariables[
> SymbolTable.StringToId("strings")] = strings;
>
> SourceUnit script = engine.CreateScriptSourceFromString(
> @"
> puts ""Hello World! There are #{$strings.count.to_s} strings:""
> $strings.each_with_index { |s,i| puts ""#{i}: #{s}"" }
> ");
>
> Console.WriteLine("Executing from string:");
> engine.Execute(scope, script);
>
> }
> }
>
>
>
> On Jan 28, 2008 12:16 PM, Greg Akins <angrygreg at gmail.com> wrote:
>
> > OK, so I couldn't get some of the simple examples of using RubyEngine
> > to start calling Ruby from C#...
> >
> > So I spent a bit reading through the mailing list archives (realizing
> > while doing that, that I'd asked a frequently asked question).
> >
> > Now, I hope I'm not asking another stupid question.
> >
> > I found another post (
> > http://rubyforge.org/pipermail/ironruby-core/2008-January/000616.html
> > ) that suggests a method of running Ruby.
> >
> > However, I get an error on this line
> >
> > IScriptEngine engine = IronRuby.GetEngine(runtime);
> >
> > Which shows this stack trace
> >
> > at System.RuntimeMethodHandle._InvokeConstructor(Object[] args,
> > SignatureStruct& signature, IntPtr declaringType)
> > at System.RuntimeMethodHandle.InvokeConstructor(Object[] args,
> > SignatureStruct signature, RuntimeTypeHandle declaringType)
> > at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags
> > invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
> > at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr,
> > Binder binder, Object[] args, CultureInfo culture, Object[]
> > activationAttributes)
> > at System.Activator.CreateInstance(Type type, BindingFlags
> > bindingAttr, Binder binder, Object[] args, CultureInfo culture,
> > Object[] activationAttributes)
> > at System.Activator.CreateInstance(Type type, Object[] args)
> > at Microsoft.Scripting.Utils.ReflectionUtils.CreateInstance[T](Type
> > actualType, Object[] args) in
> >
> > c:\Libraries\IronRuby\trunk\src\microsoft.scripting\Utils\ReflectionUtils.cs:line
> > 127
> >
> > --
> > Greg Akins
> > Software Development Manager
> > SSI Services
> >
> > http://kc.vanadium.com
> > http://www.pghcodingdojo.org
> > http://www.insomnia-consulting.org/monologue
> > _______________________________________________
> > Ironruby-core mailing list
> > Ironruby-core at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/ironruby-core
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/ironruby-core/attachments/20080128/70f7e867/attachment-0001.html
More information about the Ironruby-core
mailing list