After playing around with this I think what Simon and Jean-Sebastien have
already said is correct, its the ".new" that does it. Right now the
createInstance method is:

   public RubyScriptInstance createScriptInstance() {
       return new RubyScriptInstance(rubyEngine.evalScript(getScript()),
responseClasses);
   }

Assuming you add a class attribute to the scdl and store that value in a
className field in RubyScript then I think the following should work:

   public RubyScriptInstance createScriptInstance() {
       IRubyObject  rubyInstance = rubyEngine.evalScript(getScript());
       if (className != null) {
           rubyInstance = rubyEngine.evalScript (className + ".new");
       }
       return new RubyScriptInstance(rubyInstance , responseClasses);
   }

  ...ant



On 9/8/06, Jean-Sebastien Delfino <[EMAIL PROTECTED]> wrote:

Venkata Krishnan wrote:
> Hi
>
> The current implementation of Ruby in Java works only for scripts that
> have
> global methods.  I am interested getting this work for methods inside
> classes.. But then I am not able to figure out a way of doing this.
>
> Can somebody help me with clues on the following... maybe even if the
C++
> guys are able to provide me some hints conceptually I can map it to the
> JRuby stuff.  Here is what I do...
>
> 1) I load the script into the Ruby engine and get a RubyObject out of it
> 2) call the invoke method on the Ruby object to invoke the Ruby
functions
>    - in this invoke method there is no way I am able to specify the
> RubyClass whos method I should invoke.  All that it takes is the
> method name
> as a string.  I tried using <ruby classname>.<ruby methodname> for the
> method argument but failed.
>
> So how do I specify the class?
>
> Thanks
>
> - Venkat
>
> On 9/8/06, Simon Laws < [EMAIL PROTECTED]> wrote:
>>
>> On 9/8/06, ant elder < [EMAIL PROTECTED]> wrote:
>> >
>> > Yes we should be able to do the same type of thing with Java. Is
>> the PHP
>> > SDO
>> > API the same as the C++ API or is it simplified?
>> >
>> > I think for most if not all the Java based scripting languages we can
>> just
>> > expose the Java SDO API to the scripting language (at one point we
>> had a
>> > JavaScript version of the Big Bank sample account module that did
>> this),
>> > but
>> > there are probably ways to use the dynamic nature of the script
>> languages
>> > to
>> > come up with a simplify SDO API.
>> >
>> >    ...ant
>> >
>> > On 9/7/06, Simon Laws <[EMAIL PROTECTED]> wrote:
>> > >
>> > > > In PHP we have an implementation of SDO that is fully based on
the
>> C++
>> > > SDO
>> > > > implementation. I'm not sure if it will be instructive in the
java
>> > space
>> > > but
>> > > > we have pretty much just wrapped the C++ SDO interfaces and
>> exposed
>> > them
>> > > as
>> > > > native PHP objects. I guess you would have to do a similar
>> thing in
>> > Ruby
>> > > or
>> > > > any other extension for that matter. The solution will depend
>> on how
>> > you
>> > > > construct extensions to your scripting language. In PHP it just
so
>> > > happens
>> > > > you have to do it in C/C++ but I would hope you can do it in Java
>> for
>> > > JVM
>> > > > based environments.
>> > > >
>> > >
>> > >
>> > > S
>> > >
>> > >
>> >
>> > The SDO API in PHP is fairly similar to the C++ SDO but is simplified
>> and
>> in particular it tries to take avantage of the features of PHP so
>> that it
>> is
>> comfortable to use for the PHP programmer. For example, a typical
>> user of
>> the XML DAS might do
>>
>> $xmldas->addTypes("company.xsd ");
>> $document = $xmldas->loadFile("company.xml");
>> $company = $document->getRootDataObject();
>> $company_name = $company->name;     // property access style
>> $company_name = $company['name'];   // associative array access style
>> $company_name = $company[0];        // index array access style
>>
>> The trick is make the experience as natural for the script developer
>> as possible so we have, for example,  provided all the normal PHP
>> object access styles.
>>
>> Also our user space implementation of the relational DAS is quite
>> different from the current java implementation.
>>
>> Regards
>>
>> Simon
>>
>>
>
Venkat,

I'm not sure how you do with thiw JRuby, but you should call the target
method on an instance of the Ruby component implementation class, not on
the class itself. So do something like:
1. invoke "Calculator.new" and get an object representing your Ruby object
2. get an object representing the "add" method
3. invoke that method on the Ruby instance

--
Jean-Sebastien


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Reply via email to