[Ironruby-core] ironruby hosting as scripting engine

Kevin Radcliffe kevin.radcliffe at gmail.com
Fri Nov 6 14:35:44 EST 2009


Thanks Dotan.

Personally, I have a bit of a hacky solution:

I have a wrapper class with 2 functions SetScriptInput and GetScriptOutput.
These pass and retrieve 2 scope level variables "callerInput" and
"callerOutput" (names are arbitrary)

The internal scripts expect and deal with these variables calling them through:
self.callerInput and self.callerOutput.

It works just fine, but I think I'll give your method a try as well.
It looks like there will be less artifacts in the script using it
(which would be nice)

Best Regards,
Kevin


On Fri, Nov 6, 2009 at 12:16 PM, Dotan N. <dipidi at gmail.com> wrote:
> Hi guys sorry for the lengthy mail but i believe this is interesting since
> i've found a solution that someone else could use.
>
> just had a session of trying to embed IR in my application.
> I'm defining a user script which contains some initialization code and a
> special worker function 'execute'
>
> this is the "user script":
>
> script1.s --------------------------------------------------------
> $script.declare "version 1"
>
> def execute
>    $script.report "success"
> end
> --------------------------------------------------------
>
>
> what i'm doing is setting "script" as a global variable that is a gateway to
> my application.
> I've tried this way first:
>
> wrapping script1.s with "class Script <scriopt1.s content> end"
> and doing Engine.Execute on it.
>
> I expected to get a RubyObject as a result, which is the Script class.
>
> then with the RubyObject i would do ObjectOperations.Invoke("execute"); when
> ever i wish.
>
> I had 2 problems:
>
> 1. the RubyObject was always null. any idea why?
> 2. I couldn't really define a global variable properly (i've used the $a = a
> trick from the forum)
>
>
>
> eventually i've realized this solution:
> 1. set global variable via RubyContext.DefineGlobalVariable
> 2.  i run everything on my script scope and Execute script1.s directly given
> a ScriptScope
> 3. do InvokeMember on the ScriptScope itself
>
>
> from googling i've noticed the solution changed a lot along time.
> so what is the proper way to do it?
>
>
> Thanks!
>
>
>
>
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
>
>


More information about the Ironruby-core mailing list