Package com.scriptbasic
Class Engine
java.lang.Object
com.scriptbasic.Engine
- All Implemented Interfaces:
ScriptBasic
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface com.scriptbasic.api.ScriptBasic
ScriptBasic.FunctionBuilder, ScriptBasic.VariableBuilder -
Field Summary
Fields inherited from interface com.scriptbasic.api.ScriptBasic
fileHandlingFunctionsClass -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionEvaluate the content of a file.Read the content of a stream provided by the reader and interpret this as a BASIC program.Evaluate a string as a BASIC program.eval(String sourceFileName, SourcePath path) Read the content of the file and execute it.eval(String sourceName, SourceProvider provider) Read the content of the source from the file, db...Read the content of the file and execute it.execute()Execute a previously loaded code.Get the output writer used to write the error output of the BASIC program.getInput()Get the reader from where the BASIC program reads the standard input characters.Get the output writer used to write the standard output of the BASIC program.getVariable(String name) Get the value of a global variable after the BASIC program was executed.Same asScriptBasic.variables().Evaluate the content of a file.Read the content of a stream provided by the reader and interpret this as a BASIC program.Load a string as a BASIC program.load(String sourceFileName, SourcePath path) Read the content of the file and execute it.load(String sourceName, SourceProvider provider) Read the content of the source from the file, db...Read the content of the file and execute it.registerExtension(Class<?> klass) Register the static methods of the class as BASIC functions.voidregisterFunction(String alias, Class<?> klass, String methodName, Class<?>... argumentTypes) registerHook(InterpreterHook hook) Register an interpreter hook class.voidsetErrorOutput(Writer error) Set the output writer used to write the error output of the BASIC program.voidSet the reader from where the BASIC program reads the standard input characters.voidSet the output writer used to write the standard output of the BASIC program.voidsetVariable(String name, Object value) Set the value of a global variable of the BASIC program.<R> Subroutine<R> subroutine(Class<R> type, String name) Get the subroutine object of a named subroutine.<R> Subroutine<R> subroutine(String name) Convenience method with the same result as callingScriptBasic.subroutine(Class, String)withObject.classas first argument.Get all the subroutine objects in an iterator.<T> TGet the value of a global variable after the BASIC program was executed.Get an iterator that iterates through the names of the global variables.
-
Constructor Details
-
Engine
public Engine()
-
-
Method Details
-
getInput
Description copied from interface:ScriptBasicGet the reader from where the BASIC program reads the standard input characters.- Specified by:
getInputin interfaceScriptBasic- Returns:
- return value
-
setInput
Description copied from interface:ScriptBasicSet the reader from where the BASIC program reads the standard input characters.- Specified by:
setInputin interfaceScriptBasic- Parameters:
input- the input to set
-
getOutput
Description copied from interface:ScriptBasicGet the output writer used to write the standard output of the BASIC program.- Specified by:
getOutputin interfaceScriptBasic- Returns:
- the output
-
setOutput
Description copied from interface:ScriptBasicSet the output writer used to write the standard output of the BASIC program.- Specified by:
setOutputin interfaceScriptBasic- Parameters:
output- parameter
-
getErrorOutput
Description copied from interface:ScriptBasicGet the output writer used to write the error output of the BASIC program.- Specified by:
getErrorOutputin interfaceScriptBasic- Returns:
- the error output writer
-
setErrorOutput
Description copied from interface:ScriptBasicSet the output writer used to write the error output of the BASIC program.- Specified by:
setErrorOutputin interfaceScriptBasic- Parameters:
error- the error output
-
execute
Description copied from interface:ScriptBasicExecute a previously loaded code.- Specified by:
executein interfaceScriptBasic- Returns:
- this
- Throws:
ScriptBasicException- in case of exception
-
load
Description copied from interface:ScriptBasicLoad a string as a BASIC program.- Specified by:
loadin interfaceScriptBasic- Parameters:
sourceCode- contains the source code as string- Returns:
- this
- Throws:
ScriptBasicException- when the code cannot be loaded
-
eval
Description copied from interface:ScriptBasicEvaluate a string as a BASIC program.- Specified by:
evalin interfaceScriptBasic- Parameters:
sourceCode- contains the source code as string- Returns:
- this
- Throws:
ScriptBasicException- in case of exception
-
load
Description copied from interface:ScriptBasicRead the content of a stream provided by the reader and interpret this as a BASIC program. This method does not execute the code.- Specified by:
loadin interfaceScriptBasic- Parameters:
reader- the reader to supply the BASIC program characters.- Returns:
- this
- Throws:
ScriptBasicException- when the code cannot be loaded
-
eval
Description copied from interface:ScriptBasicRead the content of a stream provided by the reader and interpret this as a BASIC program.- Specified by:
evalin interfaceScriptBasic- Parameters:
reader- the reader to supply the BASIC program characters.- Returns:
- this
- Throws:
ScriptBasicException- in case of exception
-
load
Description copied from interface:ScriptBasicEvaluate the content of a file. The file has to contain the BASIC program. This method does not execute the code.- Specified by:
loadin interfaceScriptBasic- Parameters:
sourceFile- the file handler pointing to the file that the interpreter will read to get the source code.- Returns:
- this
- Throws:
ScriptBasicException- in case of exception
-
eval
Description copied from interface:ScriptBasicEvaluate the content of a file. The file has to contain the BASIC program.- Specified by:
evalin interfaceScriptBasic- Parameters:
sourceFile- the file handler pointing to the file that the interpreter will read to get the source code.- Returns:
- this
- Throws:
ScriptBasicException- in case of exception
-
load
Description copied from interface:ScriptBasicRead the content of the file and execute it. If there is any other script included then use the path to search for the file. This method does not execute the code.- Specified by:
loadin interfaceScriptBasic- Parameters:
sourceFileName- the file that contains the scriptpath- the array of path elements that are searched for included files- Returns:
- this
- Throws:
ScriptBasicException- in case of exception
-
eval
Description copied from interface:ScriptBasicRead the content of the file and execute it. If there is any other script included then use the path to search for the file.- Specified by:
evalin interfaceScriptBasic- Parameters:
sourceFileName- the file that contains the scriptpath- the array of path elements that are searched for included files- Returns:
- this
- Throws:
ScriptBasicException- in case of exception
-
load
Description copied from interface:ScriptBasicRead the content of the file and execute it. If there is any other script included then use the path to search for the file. This method does not execute the code.- Specified by:
loadin interfaceScriptBasic- Parameters:
sourceFileName- the file that contains the scriptpath- the path where included files are located- Returns:
- this
- Throws:
ScriptBasicException- in case of exception
-
eval
Description copied from interface:ScriptBasicRead the content of the file and execute it. If there is any other script included then use the path to search for the file.- Specified by:
evalin interfaceScriptBasic- Parameters:
sourceFileName- the file that contains the scriptpath- the path where included files are located- Returns:
- this
- Throws:
ScriptBasicException- in case of exception
-
load
Description copied from interface:ScriptBasicRead the content of the source from the file, db... whatever named by the argumentsourceNameusing the provider. This method does not execute the code.- Specified by:
loadin interfaceScriptBasic- Parameters:
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 content- Returns:
- this
- Throws:
ScriptBasicException- in case of exception
-
eval
Description copied from interface:ScriptBasicRead the content of the source from the file, db... whatever named by the argumentsourceNameusing the provider.- Specified by:
evalin interfaceScriptBasic- Parameters:
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 content- Returns:
- this
- Throws:
ScriptBasicException- in case of exception
-
setVariable
Description copied from interface:ScriptBasicSet the value of a global variable of the BASIC program.- Specified by:
setVariablein interfaceScriptBasic- Parameters:
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.- Throws:
ScriptBasicException- in case of exception
-
getVariable
Description copied from interface:ScriptBasicGet the value of a global variable after the BASIC program was executed.- Specified by:
getVariablein interfaceScriptBasic- Parameters:
name- of the variable- Returns:
- the value of the variable converted to Java. Thus there is no
need to deal with ScriptBasic internal classes. If the variable
contains an integer then this method will return a
Long, if it is a string then it will be aStringand so on. - Throws:
ScriptBasicException- in case of exception
-
variable
Description copied from interface:ScriptBasicGet the value of a global variable after the BASIC program was executed.- Specified by:
variablein interfaceScriptBasic- Type Parameters:
T- the type the caller expects the variable to be. Type conversion is done by the method and in case the value can not be cast to the type then the ClassCastException will be embedded into a ScriptBasicException. This method will not magically convert between Java types, even though it will convert from BASIC types to Java types (see below). This parameter is used only to cast the result.- Parameters:
type- is the type classname- of the variable- Returns:
- the value of the variable converted to Java. Thus there is no
need to deal with ScriptBasic internal classes. If the variable
contains an integer then this method will return a
Long, if it is a string then it will be aStringand so on. - Throws:
ScriptBasicException- when the variable cannot be retrieved, or has a type that can not be converted toT.
-
getVariablesIterator
Description copied from interface:ScriptBasicSame asScriptBasic.variables().- Specified by:
getVariablesIteratorin interfaceScriptBasic- Returns:
- same as
- Throws:
ScriptBasicException- in case of exception
-
variables
Description copied from interface:ScriptBasicGet an iterator that iterates through the names of the global variables.- Specified by:
variablesin interfaceScriptBasic- Returns:
- the iterator to fetch the names of the global variables one by one.
- Throws:
ScriptBasicException- in case of exception
-
subroutines
Description copied from interface:ScriptBasicGet all the subroutine objects in an iterator.- Specified by:
subroutinesin interfaceScriptBasic- Returns:
- an iterator that can be used to access all subroutine objects.
- Throws:
ScriptBasicException- in case of exception
-
subroutine
Description copied from interface:ScriptBasicConvenience method with the same result as callingScriptBasic.subroutine(Class, String)withObject.classas first argument.- Specified by:
subroutinein interfaceScriptBasic- Type Parameters:
R- defaults toObject.class- Parameters:
name- the name of the subroutine- Returns:
- the subroutine object
- Throws:
ScriptBasicException- in case of exception
-
subroutine
Description copied from interface:ScriptBasicGet the subroutine object of a named subroutine. This object can later be used to call the subroutine after the code was executed.- Specified by:
subroutinein interfaceScriptBasic- Type Parameters:
R- the type- Parameters:
type- is the expected return value of the subroutine. If the subroutine does not return any value then specifyVoid.class. If it may return just any value, or may not return any value and the caller does not care then specifyObject.classor justnull. Note that this is an error if a subroutine returns a value when invokingSubroutine.call()but the subroutine object was created withVoid.classargument.name- the name of the subroutine for which the object is to be fetched.- Returns:
- the subroutine object.
- Throws:
ScriptBasicException- in case of exception
-
registerFunction
public void registerFunction(String alias, Class<?> klass, String methodName, Class<?>... argumentTypes) throws ScriptBasicException - Specified by:
registerFunctionin interfaceScriptBasic- Parameters:
alias- the name of the method as it can be used in the BASIC programklass- the class that contains the methodmethodName- the name of the methodargumentTypes- the types of the arguments- Throws:
ScriptBasicException- when a function is double defined and not an identical manner
-
registerExtension
Description copied from interface:ScriptBasicRegister the static methods of the class as BASIC functions. After the registration, the methods can be called from BASIC just as if they were built-in functions in the language or just like if they were defined as BASIC subroutines.The registration process uses only the methods that are annotated as
BasicFunctionand only if theirBasicFunction.classification()parameter is not configured in the configuration 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
publicand their packages exported to the BASIC interpreter.- Specified by:
registerExtensionin interfaceScriptBasic- Parameters:
klass- the class to parse.- Returns:
- this
-
registerHook
Description copied from interface:ScriptBasicRegister an interpreter hook class.- Specified by:
registerHookin interfaceScriptBasic- Parameters:
hook- the hook instance to register- Returns:
- this
-
getConfiguration
- Specified by:
getConfigurationin interfaceScriptBasic- Returns:
- the configuration object of the BASIC interpreter.
-