On 9/8/06, Venkata Krishnan <[EMAIL PROTECTED]> 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
>
>


Hi Venkat

I'm not sure that this helps at all but I just took a look at what Sebastien
did in C++

                   string expr = impl->getClass() + ".new";
                   VALUE instance = rb_eval_string(expr.c_str());

                   // Get the ID of the specified method
                   ID method = rb_intern(operation.getName().c_str());

When it comes time to actually call the method

                   // Invoke the specified method
                   VALUE value;
                   if (n == 0)
                   {
                       value = rb_funcall(instance, method, 0);
                   }
                   else
                   {
                       value = rb_funcall2(instance, method, n, args);
                   }

So he seems to be able to deal with the class instance in C++. This is the
script he used to test with in the C++ Calculator sample.

class DivideImpl

 def initialize()
   print "Ruby - DivideImpl.initialize\n"
 end

 def divide(arg1, arg2)
   print "Ruby - DivideImpl.divide\n"
   arg1 / arg2
 end

end

Sebastien is the man to ask really as he build the Ruby extension. He will
be able to give you the gory details no doubt when he comes on line.

S

Reply via email to