We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › Help calling a class method from beanscript
Page Index Toggle Pages: 1
Help calling a class method from beanscript (Read 547 times)
Help calling a class method from beanscript
Jan 1st, 2009, 3:20am
 
Hello!

I'm having trouble passing an object to a beanscript interpreter, then calling a method from that object from within a beanscript file.  

I have a class named "Pattern", and I'm trying to send in an object of this class into the Interpreter using the bsh.Interpreter::set(String,Object) method.

Here's "my" code.  (Most of it is copied from an Interpreter wrapper that was posted as part of an example for live coding.)

Here's the basics of the Interpreter wrapper.  

Code:


class Interpreter {
bsh.Interpreter ip = null;

Interpreter(){
ip = new bsh.Interpreter();
ip.eval("import processing.core.*;");
}

public void setPattern(String name, Pattern obj){
try{
ip.set(name, obj);
}
catch(bsh.EvalError e){
println(e);
}
}
}



Here's my code that calls it:

Code:


File setupScript = new File(dataPath("setup.bsh"));

// draft_sequencer1.get_pattern() returns a Pattern object
ip.setPattern("p1", draft_sequencer1.get_pattern());

ip.call(setupScript);



Here's setup.bsh (my beanscript):

Code:


p1.shrink(5); // shrink is a method of Pattern



Here's the error that I keep getting:

Code:


Sourced file: C:\Documents and Settings\Bret Truchan\My Documents\Processing\Quotile\data\setup.bsh : Error in method invocation: Method shrink( int ) not found in class'Quotile$Pattern' : at Line: 1 : in file: C:\Documents and Settings\Bret Truchan\My Documents\Processing\Quotile\data\setup.bsh : p1 .shrink ( 5 )



Just for giggles, here's a portion of class Pattern:

Code:


class Pattern
{
void shrink(int percentage)
{
this.stretch(-1 * percentage);
}
}



Any ideas why beanscript is unable to locate the shrink method in p1?
Re: Help calling a class method from beanscript
Reply #1 - Jan 1st, 2009, 3:53am
 
I think I figured it out:

ip.eval("setAccessibility(true)");

This allowed me to call the methods in the object that I passed in.  

EDIT: Everything works perfectly!  Awesome!

Thanks,
Bret
Page Index Toggle Pages: 1