Re: How to access objects from the script?
Wade Chandler <hwadechandler-beanshell-/[email protected]> Wed, 15 Mar 2006 06:12:24 -0800 (PST)
| Newsgroups | gmane.comp.java.beanshell.devel |
|---|---|
| Message-ID | <[email protected]> |
--- Philip Cammin <philip.cammin-gM/[email protected]> wrote: > Hello! > > I would like to call different methods which are > written in a beanscript > file at certain points in my application. For > example i do call the > method "on_start()" in the "public static void > main(String args[])" > method of my application. And i, ofcourse can give > the method strings > and integers, but i did not find an example to give > the method, a > reference to an object. Also i did not find out how > to modfiy objects or > variable which are in the real java code from the > script, if i only had > the reference to it. > > I just want to offer the oppertunity for the users > to get or set data in > the program at different points, i do not want to to > script the whole > classes. > > Thank you! > Read the java docs for Interpreter. Java docs are your friend as long as we're talking about hte same thing. You will be calling the scripts from your code at some point, and you'll be instantiating an Interpreter, unless some how you are using the beanshell for your main application. See the method bsh.Interpreter.set, you'll set your objects before you ever call eval or source. Beyond that if you need to have references to global objects or something from multiple interpreters in different scripts you'll have to carefully keep references in a static Map or some other container so you can get to them. Wade ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642