This is what you need to do:

public void go(Object objt, String Fname) throws EvalError {
    intp.set("objt", objt);
    intp.eval("obj." + Fname);
}


Daedalus <UNDER_NETAI@hotmail.com> wrote:

I'm new to beanshell so I don't know if this is possible but here goes.

I'm using java with an imported interpreter to evaluate a string which
contains the name of a method I want to exacute.

import bsh.EvalError;
import bsh.Interpreter;
Interpreter intp = new Interpreter();
public static void main(String[] args) throws EvalError {
Ex w = new Ex();
w.go(this,".message()")

}

public void go(Object objt, String Fname) throws EvalError {

intp.eval(objt + intp.eval(Fname));
}

public void message() {
System.out.println("works");
}

I have a go() method that is ment to take an object and string then the go()
method should evaluate the Fname to convert the string to a method and
combine it with my object and execute it.

so it would look like objt.message();

however the intepreter produces this error

at bsh.Interpreter.eval(Unknown Source)

Could someone point me in the right direction or tell me an alternative way
of doing this?

Thanks
--
View this message in context: http://www.nabble.com/converting-a-string-to-method-and-executing-it-tf2063741.html#a5685284
Sent from the BeanShell - User forum at Nabble.com.


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Beanshell-users mailing list
Beanshell-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/beanshell-users



Alexey
2001 Honda CBR600F4i (CCS)
1992 Kawasaki EX500
http://azinger.blogspot.com
http://bsheet.sourceforge.net


Yahoo! Music Unlimited - Access over 1 million songs. Try it free.