Modifier and Type | Class and Description |
---|---|
class |
Engine.Sub |
Constructor and Description |
---|
Engine() |
Modifier and Type | Method and Description |
---|---|
Object |
call(String subroutineName,
Object... args)
Call the named subroutine with the arguments.
|
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)
Get the number of expected argument of the named subroutine.
|
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.
|
public Factory getBasicFactory()
EngineApi
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.
getBasicFactory
in interface EngineApi
public Reader getInput()
EngineApi
public void setInput(Reader input)
EngineApi
public Writer getOutput()
EngineApi
public void setOutput(Writer output)
EngineApi
public Writer getError()
EngineApi
public void setError(Writer error)
EngineApi
public void execute() throws ScriptBasicException
EngineApi
execute
in interface EngineApi
ScriptBasicException
public void load(String sourceCode) throws ScriptBasicException
EngineApi
load
in interface EngineApi
sourceCode
- contains the source code as stringScriptBasicException
public void eval(String sourceCode) throws ScriptBasicException
EngineApi
eval
in interface EngineApi
sourceCode
- contains the source code as stringScriptBasicException
public void load(Reader reader) throws ScriptBasicException
EngineApi
load
in interface EngineApi
reader
- the reader to supply the BASIC program characters.ScriptBasicException
public void eval(Reader reader) throws ScriptBasicException
EngineApi
eval
in interface EngineApi
reader
- the reader to supply the BASIC program characters.ScriptBasicException
public void load(File sourceFile) throws ScriptBasicException
EngineApi
load
in interface EngineApi
sourceFile
- the file handler pointing to the file that the interpreter
will read to get the source code.ScriptBasicException
public void eval(File sourceFile) throws ScriptBasicException
EngineApi
eval
in interface EngineApi
sourceFile
- the file handler pointing to the file that the interpreter
will read to get the source code.ScriptBasicException
public void load(String sourceFileName, String... path) throws ScriptBasicException
EngineApi
load
in interface EngineApi
sourceFileName
- the file that contains the scriptpath
- the array of path elements that are searched for included
filesScriptBasicException
public void eval(String sourceFileName, String... path) throws ScriptBasicException
EngineApi
eval
in interface EngineApi
sourceFileName
- the file that contains the scriptpath
- the array of path elements that are searched for included
filesScriptBasicException
public void load(String sourceFileName, SourcePath path) throws ScriptBasicException
EngineApi
load
in interface EngineApi
sourceFileName
- the file that contains the scriptpath
- the path where included files are locatedScriptBasicException
public void eval(String sourceFileName, SourcePath path) throws ScriptBasicException
EngineApi
eval
in interface EngineApi
sourceFileName
- the file that contains the scriptpath
- the path where included files are locatedScriptBasicException
public void load(String sourceName, SourceProvider provider) throws ScriptBasicException
EngineApi
sourceName
using the provider. This method does not
execute the code.load
in interface EngineApi
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
public void eval(String sourceName, SourceProvider provider) throws ScriptBasicException
EngineApi
sourceName
using the provider.eval
in interface EngineApi
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
public void setVariable(String name, Object value) throws ScriptBasicException
EngineApi
setVariable
in interface EngineApi
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
public Object getVariable(String name) throws ScriptBasicException
EngineApi
getVariable
in interface EngineApi
name
- of the variableLong
,
if it is a string then it will be a String
and so on.ScriptBasicException
public Iterable<String> getVariablesIterator()
EngineApi
getVariablesIterator
in interface EngineApi
public Object call(String subroutineName, Object... args) throws ScriptBasicException
EngineApi
It is recommended to call subroutines via a
Subroutine
object.
call
in interface EngineApi
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
public Iterable<String> getSubroutineNames()
EngineApi
getSubroutineNames
in interface EngineApi
public Iterable<Subroutine> getSubroutines()
EngineApi
getSubroutines
in interface EngineApi
public int getNumberOfArguments(String subroutineName) throws ScriptBasicException
EngineApi
It is recommended to call subroutines via a
Subroutine
object.
getNumberOfArguments
in interface EngineApi
subroutineName
- the name of the subroutine.ScriptBasicException
public Subroutine getSubroutine(String subroutineName) throws ScriptBasicException
EngineApi
getSubroutine
in interface EngineApi
subroutineName
- the name of the subroutine for which the object is to be
fetched.ScriptBasicException
public void registerExtension(Class<?> klass) throws ScriptBasicException
EngineApi
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
.
registerExtension
in interface EngineApi
klass
- the class to parse.ScriptBasicException
Copyright © 2013 Verhas and Verhas Software Craftsmen. All Rights Reserved.