Home |
Back |
Contents |
Next |
// File: helloWorld.bsh helloWorld() { print("Hello World!"); } |
addClassPath("/home/pat"); // If it's not already in our classpath importCommands("/mycommands"); |
helloWorld(); // prints "Hello World!" |
// equivalent importCommands("com.xyz.utils"); importCommands("/com/xyz/utils"); |
// File: helloWorld.bsh helloWorld() { print("Hello World!"); } helloWorld( String msg ) { print("Hello World: "+msg); } |
/** Implement dir() command. */ public static void invoke( Interpreter env, CallStack callstack ) { String dir = "."; invoke( env, callstack, dir ); } /** Implement dir( String directory ) command. */ public static void invoke( Interpreter env, CallStack callstack, String dir ) { ... } |
invoke( String methodName, Object [] arguments ) { print("You invoked the method: "+ methodName ); } // invoke() will be called to handle noSuchMethod() noSuchMethod("foo"); |
Note: Note that this means that currently scripted commands may only be loaded once and then they are effectively cached. |
fooSetter() { this.caller.foo=42; } |
fooSetter(); print( foo ); // 42 |
foo() { ... } foo(); |
foo() { bar() { ... } ... } // somewhere fooObject.bar(); |
eval("a=5"); print( a ); // 5 |
eval( String text ) { this.interpreter.eval( text, this.caller.namespace ); } |
this.caller.caller...; |
myCommand() { // "Step into" the caller's namespace. setNameSpace( this.caller.namespace ); // work as if we were in the caller's namespace. } |
object = object(); // save our namespace savedNameSpace = this.namespace; // step into object's namespace setNameSpace( object.namespace ); // Work in the object's scope a=1; b=2; // step back setNameSpace( savedNameSpace ); print( object.a ); // 1 print( object.b ); // 2 print( a ); // ERROR! undefined |
assert( boolean condition ) { if ( condition ) print( "Test Passed..." ); else { print( "Test FAILED: " +"Line: "+ this.namespace.getInvocationLine() +" : "+this.namespace.getInvocationText() +" : while evaluating file: "+getSourceFileInfo() ); super.test_failed = true; } } |
absfilename = pathToFile( filename ); |
dir("c:/Windows"); // ok dir("c:\\Windows"); // ok |
javap( Date.class ); // use a class type directly javap( new Date() ); // uses class of object javap( "java.util.Date" ); // Uses string name of class javap( java.util.Date ); // Use plain class identifier |
import bsh.ClassIdentifier; if ( o instanceof ClassIdentifier ) clas = this.namespace.identifierToClass(o); if ( o instanceof String) clas = this.namespace.getClass((String)o); else if ( o instanceof Class ) clas = o; else clas = o.getClass(); |
cm = CollectionManager.getCollectionManager(); if ( cm.isBshIterable( myObject ) ) { BshIterator iterator = cm.getBshIterator( myObject ); while ( iterator.hasNext() ) i = iterator.next(); } |
Home |
Back |
Contents |
Next |