Quantcast

very simple doubt - declaring a method in the Interpreter

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

very simple doubt - declaring a method in the Interpreter

shikida
Hi

from the quickstart guide, I saw that I can declare methods just like this

>>
int addTwoNumbers( int a, int b ) {
    return a + b;
}

sum = addTwoNumbers( 5, 7 );  // 12
>>

and I saw I can declare variables and evaluate expressions using the
Interpreter just like this

>>
import bsh.Interpreter;

Interpreter i = new Interpreter();  // Construct an interpreter
i.set("foo", 5);                    // Set variables
i.set("date", new Date() );

Date date = (Date)i.get("date");    // retrieve a variable

// Eval a statement and get the result
i.eval("bar = foo*10");
System.out.println( i.get("bar") );
>>

now, my doubt is how can I declare a method using the Interpreter ?

TIA

[]

Leo K.

------------------------------------------------------------------------------
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: very simple doubt - declaring a method in the Interpreter

David Lee
  i.eval("

int addTwoNumbers( int a, int b ) {
     return a + b;
} " )




David A. Lee
[hidden email]
http://www.xmlsh.org


On 10/19/2010 11:00 PM, Leonardo K. Shikida wrote:

> Hi
>
> from the quickstart guide, I saw that I can declare methods just like this
>
> int addTwoNumbers( int a, int b ) {
>      return a + b;
> }
>
> sum = addTwoNumbers( 5, 7 );  // 12
> and I saw I can declare variables and evaluate expressions using the
> Interpreter just like this
>
> import bsh.Interpreter;
>
> Interpreter i = new Interpreter();  // Construct an interpreter
> i.set("foo", 5);                    // Set variables
> i.set("date", new Date() );
>
> Date date = (Date)i.get("date");    // retrieve a variable
>
> // Eval a statement and get the result
> i.eval("bar = foo*10");
> System.out.println( i.get("bar") );
> now, my doubt is how can I declare a method using the Interpreter ?
>
> TIA
>
> []
>
> Leo K.
>
> ------------------------------------------------------------------------------
> Download new Adobe(R) Flash(R) Builder(TM) 4
> The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly
> Flex(R) Builder(TM)) enable the development of rich applications that run
> across multiple browsers and platforms. Download your free trials today!
> http://p.sf.net/sfu/adobe-dev2dev
> _______________________________________________
> Beanshell-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/beanshell-users

------------------------------------------------------------------------------
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Loading...