public interface ScriptBasic
This interface defines the native methods that can be used to embed ScriptBasic into applications. Using the methods of this API you can load, execute BASIC programs, define how the interpreter can get access to other sources that are included by the script, set and get global variables and call subroutines.
| Modifier and Type | Method | Description |
|---|---|---|
void |
eval(java.io.File sourceFile) |
Evaluate the content of a file.
|
void |
eval(java.io.Reader reader) |
Read the content of a stream provided by the reader and interpret this as
a BASIC program.
|
void |
eval(java.lang.String sourceCode) |
Evaluate a string as a BASIC program.
|
void |
eval(java.lang.String sourceFileName,
com.scriptbasic.interfaces.SourcePath path) |
Read the content of the file and execute it.
|
void |
eval(java.lang.String sourceName,
com.scriptbasic.interfaces.SourceProvider provider) |
Read the content of the source from the file, db...
|
void |
eval(java.lang.String sourceFileName,
java.lang.String... path) |
Read the content of the file and execute it.
|
void |
execute() |
Execute a previously loaded code.
|
static ScriptBasic |
getEngine() |
|
java.io.Writer |
getError() |
Get the output writer used to write the error output of the BASIC
program.
|
java.io.Reader |
getInput() |
Get the reader from where the BASIC program reads the standard input
characters.
|
java.io.Writer |
getOutput() |
Get the output writer used to write the standard output of the BASIC
program.
|
Subroutine |
getSubroutine(java.lang.String subroutineName) |
Get the subroutine object of a named subroutine.
|
java.lang.Iterable<Subroutine> |
getSubroutines() |
Get all the subroutine objects in an iterator.
|
java.lang.Object |
getVariable(java.lang.String name) |
Get the value of a global variable after the BASIC program was executed.
|
java.lang.Iterable<java.lang.String> |
getVariablesIterator() |
Get an iterator that iterates through the names of the global variables.
|
void |
load(java.io.File sourceFile) |
Evaluate the content of a file.
|
void |
load(java.io.Reader reader) |
Read the content of a stream provided by the reader and interpret this as
a BASIC program.
|
void |
load(java.lang.String sourceCode) |
Load a string as a BASIC program.
|
void |
load(java.lang.String sourceFileName,
com.scriptbasic.interfaces.SourcePath path) |
Read the content of the file and execute it.
|
void |
load(java.lang.String sourceName,
com.scriptbasic.interfaces.SourceProvider provider) |
Read the content of the source from the file, db...
|
void |
load(java.lang.String sourceFileName,
java.lang.String... path) |
Read the content of the file and execute it.
|
void |
registerExtension(java.lang.Class<?> klass) |
Register the static methods of the class as BASIC functions.
|
void |
registerFunctions(java.lang.Class<?> klass) |
Register all annotated methods of the class
klass so that they
can be accessed from BASIC. |
void |
setError(java.io.Writer error) |
Set the output writer used to write the error output of the BASIC
program.
|
void |
setInput(java.io.Reader input) |
Set the reader from where the BASIC program reads the standard input
characters.
|
void |
setOutput(java.io.Writer output) |
Set the output writer used to write the standard output of the BASIC
program.
|
void |
setVariable(java.lang.String name,
java.lang.Object value) |
Set the value of a global variable of the BASIC program.
|
static ScriptBasic getEngine()
void registerFunctions(java.lang.Class<?> klass)
throws ScriptBasicException
klass so that they
can be accessed from BASIC.klass - the class that contains the static methods to registerScriptBasicException - when a function is double defined and not an identical mannerjava.io.Reader getInput()
void setInput(java.io.Reader input)
input - java.io.Writer getOutput()
void setOutput(java.io.Writer output)
output - java.io.Writer getError()
void setError(java.io.Writer error)
error - void load(java.lang.String sourceCode) throws ScriptBasicException
sourceCode - contains the source code as stringScriptBasicExceptionvoid load(java.io.Reader reader) throws ScriptBasicException
reader - the reader to supply the BASIC program characters.ScriptBasicExceptionvoid load(java.io.File sourceFile) throws ScriptBasicException
sourceFile - the file handler pointing to the file that the interpreter
will read to get the source code.ScriptBasicExceptionvoid load(java.lang.String sourceFileName,
java.lang.String... path)
throws ScriptBasicException
sourceFileName - the file that contains the scriptpath - the array of path elements that are searched for included
filesScriptBasicExceptionvoid load(java.lang.String sourceFileName,
com.scriptbasic.interfaces.SourcePath path)
throws ScriptBasicException
sourceFileName - the file that contains the scriptpath - the path where included files are locatedScriptBasicExceptionvoid load(java.lang.String sourceName,
com.scriptbasic.interfaces.SourceProvider provider)
throws ScriptBasicException
sourceName using the provider. This method does not
execute the code.sourceName - the name of the source file where the source is. The syntax of
the name depends on the provider.provider - the source provider that helps the reader to read the contentScriptBasicExceptionvoid eval(java.lang.String sourceCode) throws ScriptBasicException
sourceCode - contains the source code as stringScriptBasicExceptionvoid eval(java.io.Reader reader) throws ScriptBasicException
reader - the reader to supply the BASIC program characters.ScriptBasicExceptionvoid eval(java.io.File sourceFile) throws ScriptBasicException
sourceFile - the file handler pointing to the file that the interpreter
will read to get the source code.ScriptBasicExceptionvoid eval(java.lang.String sourceFileName,
java.lang.String... path)
throws ScriptBasicException
sourceFileName - the file that contains the scriptpath - the array of path elements that are searched for included
filesScriptBasicExceptionvoid eval(java.lang.String sourceFileName,
com.scriptbasic.interfaces.SourcePath path)
throws ScriptBasicException
sourceFileName - the file that contains the scriptpath - the path where included files are locatedScriptBasicExceptionvoid eval(java.lang.String sourceName,
com.scriptbasic.interfaces.SourceProvider provider)
throws ScriptBasicException
sourceName using the provider.sourceName - the name of the source file where the source is. The syntax of
the name depends on the provider.provider - the source provider that helps the reader to read the contentScriptBasicExceptionvoid execute()
throws ScriptBasicException
ScriptBasicExceptionvoid setVariable(java.lang.String name,
java.lang.Object value)
throws ScriptBasicException
name - of the variable as it is used in the BASIC programvalue - the value of the variable. The value is converted
automatically to be a BASIC value.ScriptBasicExceptionjava.lang.Object getVariable(java.lang.String name)
throws ScriptBasicException
name - of the variableLong,
if it is a string then it will be a String and so on.ScriptBasicExceptionjava.lang.Iterable<java.lang.String> getVariablesIterator()
Subroutine getSubroutine(java.lang.String subroutineName) throws ScriptBasicException
subroutineName - the name of the subroutine for which the object is to be
fetched.ScriptBasicExceptionjava.lang.Iterable<Subroutine> getSubroutines()
void registerExtension(java.lang.Class<?> klass)
throws ScriptBasicException
The registration process uses only the methods that are annotated as
BasicFunction and only if their BasicFunction.classification()
parameter is not configured in the configuration file as forbidden.
Even though the static methods are called via reflection they have to be
callable from the BASIC interpreter. Simply saying they have to be
public.
klass - the class to parse.ScriptBasicExceptionCopyright © 2017 Verhas and Verhas Software Craftsmen. All Rights Reserved.