org.fraid
Class Scripting

java.lang.Object
  extended by org.fraid.Scripting

public class Scripting
extends java.lang.Object

This is Fraid's scripting interface. You can use it from Java, Jython, BeanShell, Groovy, etc. This is the easyest way to use FrAid programmatically from your Java or Java scripting environment. For efficiency direct calls to the internal functions may be better though. Use like this: org.fraid.Scripting s = new org.fraid.Scripting(); s.exec("plot('sin(x));");


Field Summary
protected  Fraid mInterpreter
          The local interpreter instance (you don't allocate a new one each time you need one).
 
Constructor Summary
Scripting()
           
 
Method Summary
 DefinedFunction def_f(java.lang.String aScript)
          Define a FrAid function.
 Complex exec(java.lang.String aScript)
          Execute a FrAid script.
static ComplexFunction get_f(java.lang.String aFunctionName)
          Get the function with name aFunctionName and aNumberOfArguments number of arguments.
 Fraid getInterpreter()
          Get the interpreter.
 SymbolTable getSymbTable()
          In case you need it directly.
static java.util.ArrayList<java.lang.String> query_f(java.lang.String aFunctionNameLike)
          Query the symbol table for functions whose name starts with aFunctionNameLike.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mInterpreter

protected Fraid mInterpreter
The local interpreter instance (you don't allocate a new one each time you need one).

Constructor Detail

Scripting

public Scripting()
Method Detail

getInterpreter

public Fraid getInterpreter()
Get the interpreter.

Returns:
a Fraid value

exec

public Complex exec(java.lang.String aScript)
             throws ParseException
Execute a FrAid script. Can process multiple expressions separated by ';' (which is FrAid's EOL symbol)

Parameters:
aScript - a String value
Returns:
a Complex value
Throws:
ParseException - if an error occurs

def_f

public DefinedFunction def_f(java.lang.String aScript)
                      throws ParseException
Define a FrAid function. Adds it to the symbol table. The difference with exec is that exec doesn't return a DefinedFunction instance. If a multiline expression is passed only the last function definition is returned. Example: org.fraid.Scripting.def_f("f(x)=sin(x)^cos(x);g(x)=f(f(x));"); will register both f(x) and g(x) in the symbol table but will return only a reference to g(x).

Parameters:
aScript - a String value
Returns:
a DefinedFunction value
Throws:
ParseException - if an error occurs
See Also:
exec

get_f

public static ComplexFunction get_f(java.lang.String aFunctionName)
                             throws SymbTableException
Get the function with name aFunctionName and aNumberOfArguments number of arguments. In FrAid only the name-number_of_arguments pair uniquely identifyes a function.

Parameters:
aFunctionName - a String value
aNumberOfArguments - an int value
Returns:
a ComplexFunction value
Throws:
SymbTableException - if an error occurs

query_f

public static java.util.ArrayList<java.lang.String> query_f(java.lang.String aFunctionNameLike)
                                                     throws SymbTableException
Query the symbol table for functions whose name starts with aFunctionNameLike. Once you get them you can filter for desired number or arguments. Then you can use get_f() to get the actual function(s).

Throws:
SymbTableException
See Also:
get_f

getSymbTable

public SymbolTable getSymbTable()
                         throws SymbTableException
In case you need it directly.

Returns:
a SymbTable value
Throws:
SymbTableException - if an error occurs


Fraid (system and language). (C) 2003-2007 Ivaylo Iliev
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.