[Ironruby-core] Busy Day with IronRuby
Michael Letterle
michael.letterle at gmail.com
Sun Jan 27 18:34:12 EST 2008
I'm actually getting ready to work on an IronRuby quick start blog
post, based on my experiences, but this is the simplest "hello world"
using the hosting mechanism I could come up with:
using System;
using Ruby.Runtime;
using Microsoft.Scripting.Hosting;
namespace RubyExample
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
IScriptEnvironment scriptenvironment =
ScriptEnvironment.GetEnvironment();
IScriptEngine rubyengine = scriptenvironment.GetEngine("ruby");
scriptenvironment.ExecuteSourceUnit(rubyengine.CreateScriptSourceFromString("puts
'Hello World!\nPress Any Key To Continue..'") );
Console.ReadKey();
}
}
}
be sure to add references to Microsof.Scripting.dll and IronRuby.dll
(and IronRuby.Libraries.dll if you're so inclined).
You can also use scriptenvironment.ExecuteFile(pathtofile) if you have
your ruby script inn a standalone file.
On Jan 27, 2008 6: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
>
--
Michael Letterle
[Polymath Programmer]
http://michaeldotnet.blogspot.com
More information about the Ironruby-core
mailing list