public interface EngineApi
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 and Description |
---|---|
Object |
call(String subroutineName,
Object... args)
Deprecated.
|
void |
eval(File sourceFile)
Evaluate the content of a file.
|
void |
eval(Reader reader)
Read the content of a stream provided by the reader and interpret this as
a BASIC program.
|
void |
eval(String sourceCode)
Evaluate a string as a BASIC program.
|
void |
eval(String sourceFileName,
SourcePath path)
Read the content of the file and execute it.
|
void |
eval(String sourceName,
SourceProvider provider)
Read the content of the source from the file, db...
|
void |
eval(String sourceFileName,
String... path)
Read the content of the file and execute it.
|
void |
execute()
Execute a previously loaded code.
|
Factory |
getBasicFactory()
Get the factory used to create the different parts of the execution
environment for this engine.
|
Writer |
getError()
Get the output writer used to write the error output of the BASIC
program.
|
Reader |
getInput()
Get the reader from where the BASIC program reads the standard input
characters.
|
int |
getNumberOfArguments(String subroutineName)
Deprecated.
|
Writer |
getOutput()
Get the output writer used to write the standard output of the BASIC
program.
|
Subroutine |
getSubroutine(String subroutineName)
Get the subroutine object of a named subroutine.
|
Iterable<String> |
getSubroutineNames()
Get the names of all subroutines.
|
Iterable<Subroutine> |
getSubroutines()
Get all the subroutine objects in an iterator.
|
Object |
getVariable(String name)
Get the value of a global variable after the BASIC program was executed.
|
Iterable<String> |
getVariablesIterator()
Get an iterator that iterates through the names of the global variables.
|
void |
load(File sourceFile)
Evaluate the content of a file.
|
void |
load(Reader reader)
Read the content of a stream provided by the reader and interpret this as
a BASIC program.
|
void |
load(String sourceCode)
Load a string as a BASIC program.
|
void |
load(String sourceFileName,
SourcePath path)
Read the content of the file and execute it.
|
void |
load(String sourceName,
SourceProvider provider)
Read the content of the source from the file, db...
|
void |
load(String sourceFileName,
String... path)
Read the content of the file and execute it.
|
void |
registerExtension(Class<?> klass)
Register the static methods of the class as BASIC functions.
|
void |
setError(Writer error)
Set the output writer used to write the error output of the BASIC
program.
|
void |
setInput(Reader input)
Set the reader from where the BASIC program reads the standard input
characters.
|
void |
setOutput(Writer output)
Set the output writer used to write the standard output of the BASIC
program.
|
void |
setVariable(String name,
Object value)
Set the value of a global variable of the BASIC program.
|
Factory getBasicFactory()
If ever you need to use this method, do use it at your own risk, and inform the developers of your need so that they may consider extending this facade to accommodate your needs.
Reader getInput()
void setInput(Reader input)
input
- Writer getOutput()
void setOutput(Writer output)
output
- Writer getError()
void setError(Writer error)
error
- void load(String sourceCode) throws ScriptBasicException
sourceCode
- contains the source code as stringScriptBasicException
void load(Reader reader) throws ScriptBasicException
reader
- the reader to supply the BASIC program characters.ScriptBasicException
void load(File sourceFile) throws ScriptBasicException
sourceFile
- the file handler pointing to the file that the interpreter
will read to get the source code.ScriptBasicException
void load(String sourceFileName, String... path) throws ScriptBasicException
sourceFileName
- the file that contains the scriptpath
- the array of path elements that are searched for included
filesScriptBasicException
void load(String sourceFileName, SourcePath path) throws ScriptBasicException
sourceFileName
- the file that contains the scriptpath
- the path where included files are locatedScriptBasicException
void load(String sourceName, 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 contentScriptBasicException
void eval(String sourceCode) throws ScriptBasicException
sourceCode
- contains the source code as stringScriptBasicException
void eval(Reader reader) throws ScriptBasicException
reader
- the reader to supply the BASIC program characters.ScriptBasicException
void eval(File sourceFile) throws ScriptBasicException
sourceFile
- the file handler pointing to the file that the interpreter
will read to get the source code.ScriptBasicException
void eval(String sourceFileName, String... path) throws ScriptBasicException
sourceFileName
- the file that contains the scriptpath
- the array of path elements that are searched for included
filesScriptBasicException
void eval(String sourceFileName, SourcePath path) throws ScriptBasicException
sourceFileName
- the file that contains the scriptpath
- the path where included files are locatedScriptBasicException
void eval(String sourceName, 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 contentScriptBasicException
void execute() throws ScriptBasicException
ScriptBasicException
void setVariable(String name, 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.ScriptBasicException
Object getVariable(String name) throws ScriptBasicException
name
- of the variableLong
,
if it is a string then it will be a String
and so on.ScriptBasicException
Iterable<String> getVariablesIterator()
Subroutine getSubroutine(String subroutineName) throws ScriptBasicException
subroutineName
- the name of the subroutine for which the object is to be
fetched.ScriptBasicException
Iterable<Subroutine> getSubroutines()
Object call(String subroutineName, Object... args) throws ScriptBasicException
It is recommended to call subroutines via a
Subroutine
object.
subroutineName
- the name of the subroutine to be called.args
- the arguments to be passed to the subroutine. Note that there
has to be that many arguments passed as many arguments are
needed by the subroutine. If there are less number of actual
arguments the rest of the arguments will be undefined. If you
pass more actual arguments than the subroutine expects you
will get an exception.RightValue
but rather a Long
, Double
,
String
or similar.ScriptBasicException
Iterable<String> getSubroutineNames()
int getNumberOfArguments(String subroutineName) throws ScriptBasicException
It is recommended to call subroutines via a
Subroutine
object.
subroutineName
- the name of the subroutine.ScriptBasicException
void registerExtension(Class<?> klass) throws ScriptBasicException
The registration process uses only the methods that are annotated as
Function
and only if their Function.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.ScriptBasicException
Copyright © 2013 Verhas and Verhas Software Craftsmen. All Rights Reserved.