Package ortus.boxlang.runtime.scripting
Class BoxScriptingEngine
java.lang.Object
ortus.boxlang.runtime.scripting.BoxScriptingEngine
- All Implemented Interfaces:
Compilable
,Invocable
,ScriptEngine
The BoxScriptingEngine is the JSR-223 implementation for BoxLang. It is the
entry point for executing BoxLang code on the JVM.
- See Also:
-
Field Summary
Fields inherited from interface javax.script.ScriptEngine
ARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME
-
Constructor Summary
ConstructorsConstructorDescriptionBoxScriptingEngine
(BoxScriptingFactory boxScriptingFactory) Constructor for the BoxScriptingEngineBoxScriptingEngine
(BoxScriptingFactory boxScriptingFactory, Boolean debug) Constructor for the BoxScriptingEngine -
Method Summary
Modifier and TypeMethodDescriptionCompile a scriptCompile a scriptcreatBindings
(Map<String, Object> m) Create a new Bindings object with the given mapCreate a new Bindings objectEvaluate a script bound only to the top-level BoxRuntime contexteval
(Reader reader, ScriptContext context) Evaluate a script in the context of the ScriptContextEvaluate a script bound only to the top-level BoxRuntime contextEvaluate a script using the given Bindingseval
(String script, ScriptContext context) Evaluate a script in the context of the ScriptContextGet the defaults bindings which is the variables scope = engine scopegetBindings
(int scope) Get the bindings for the given scopeGet the BoxContext for the BoxScriptingEngineGet the ScriptContext for the BoxScriptingEngine<T> T
getInterface
(Class<T> clasz) Returns an implementation of an interface using functions compiled in the interpreter.<T> T
getInterface
(Object thiz, Class<T> clasz) Builds a dynamic proxy from the passed in object that maps to the given interface.Helper method to get the request scope bindingsGet the BoxRuntime for the BoxScriptingEngineHelper method to get the server scope bindingsinvokeFunction
(String name, Object... args) This is used when you eval a script that is a BoxLang function definition, so you can invoke it.invokeMethod
(Object thiz, String name, Object... args) This is used when you eval a script that is a BoxLang object definition.void
void
setBindings
(Bindings bindings, int scope) Set the bindings for the given scopevoid
setContext
(ScriptContext context) Set the ScriptContext for the BoxScriptingEngine
-
Constructor Details
-
BoxScriptingEngine
Constructor for the BoxScriptingEngine- Parameters:
boxScriptingFactory
- The factory for the BoxScriptingEnginedebug
- Whether to run in debug mode, defaults to false- See Also:
-
BoxScriptingEngine
Constructor for the BoxScriptingEngine- Parameters:
boxScriptingFactory
- The factory for the BoxScriptingEngine- See Also:
-
-
Method Details
-
getRuntime
Get the BoxRuntime for the BoxScriptingEngine- Returns:
- The BoxRuntime for the BoxScriptingEngine
-
eval
Evaluate a script in the context of the ScriptContext- Specified by:
eval
in interfaceScriptEngine
- Parameters:
script
- The script to evaluatecontext
- The context to evaluate the script in- Returns:
- The result of the script evaluation
- Throws:
ScriptException
-
eval
Evaluate a script in the context of the ScriptContext- Specified by:
eval
in interfaceScriptEngine
- Parameters:
reader
- The reader to read the script fromcontext
- The context to evaluate the script in- Returns:
- The result of the script evaluation
- Throws:
ScriptException
-
eval
Evaluate a script bound only to the top-level BoxRuntime context- Specified by:
eval
in interfaceScriptEngine
- Parameters:
reader
- The reader to read the script from- Returns:
- The result of the script evaluation
- Throws:
ScriptException
-
eval
Evaluate a script using the given Bindings- Specified by:
eval
in interfaceScriptEngine
- Parameters:
script
- The script to evaluaten
- The Bindings to use- Returns:
- The result of the script evaluation
- Throws:
ScriptException
-
eval
- Specified by:
eval
in interfaceScriptEngine
- Throws:
ScriptException
-
eval
Evaluate a script bound only to the top-level BoxRuntime context- Specified by:
eval
in interfaceScriptEngine
- Parameters:
script
- The script to evaluate- Returns:
- The buffer from the BoxContext
- Throws:
ScriptException
-
createBindings
Create a new Bindings object- Specified by:
createBindings
in interfaceScriptEngine
- Returns:
- A new Bindings object
-
creatBindings
Create a new Bindings object with the given map- Parameters:
m
- The map to seed the Bindings with- Returns:
- A new Bindings object with the given map
-
put
- Specified by:
put
in interfaceScriptEngine
-
get
- Specified by:
get
in interfaceScriptEngine
-
getBindings
Get the defaults bindings which is the variables scope = engine scope- Returns:
- The bindings for the given scope if found, else null
-
getRequestBindings
Helper method to get the request scope bindings -
getServerBindings
Helper method to get the server scope bindings -
getBindings
Get the bindings for the given scope- Specified by:
getBindings
in interfaceScriptEngine
- Parameters:
scope
- The scope to get the bindings for- Returns:
- The bindings for the given scope if found, else null
-
setBindings
Set the bindings for the given scope- Specified by:
setBindings
in interfaceScriptEngine
- Parameters:
bindings
- The bindings to setscope
- The scope to set the bindings for- Throws:
IllegalArgumentException
- If the scope is invalid
-
getContext
Get the ScriptContext for the BoxScriptingEngine- Specified by:
getContext
in interfaceScriptEngine
- Returns:
- The ScriptContext for the BoxScriptingEngine
-
setContext
Set the ScriptContext for the BoxScriptingEngine- Specified by:
setContext
in interfaceScriptEngine
- Parameters:
context
- The ScriptContext to set
-
getFactory
- Specified by:
getFactory
in interfaceScriptEngine
-
compile
Compile a script- Specified by:
compile
in interfaceCompilable
- Parameters:
script
- The script to compile- Returns:
- The compiled script
- Throws:
ScriptException
-
compile
Compile a script- Specified by:
compile
in interfaceCompilable
- Parameters:
script
- The script to compile- Returns:
- The compiled script
- Throws:
ScriptException
-
getBoxContext
Get the BoxContext for the BoxScriptingEngine- Returns:
- The BoxContext for the BoxScriptingEngine
-
invokeMethod
public Object invokeMethod(Object thiz, String name, Object... args) throws ScriptException, NoSuchMethodException This is used when you eval a script that is a BoxLang object definition.- Specified by:
invokeMethod
in interfaceInvocable
- Parameters:
thiz
- The object to invoke the method onname
- The name of the method to invokeargs
- The positional arguments to pass to the method- Returns:
- The result of the method invocation
- Throws:
ScriptException
NoSuchMethodException
-
invokeFunction
public Object invokeFunction(String name, Object... args) throws ScriptException, NoSuchMethodException This is used when you eval a script that is a BoxLang function definition, so you can invoke it.- Specified by:
invokeFunction
in interfaceInvocable
- Parameters:
name
- The name of the function to invokeargs
- The positional arguments to pass to the function- Returns:
- The result of the function invocation
- Throws:
ScriptException
NoSuchMethodException
-
getInterface
Returns an implementation of an interface using functions compiled in the interpreter.- Specified by:
getInterface
in interfaceInvocable
- Parameters:
clasz
- The interface to create the dynamic proxy- Returns:
- An implementation of the interface using functions compiled in the interpreter
-
getInterface
Builds a dynamic proxy from the passed in object that maps to the given interface.- Specified by:
getInterface
in interfaceInvocable
- Parameters:
thiz
- The object to create the proxy from. This can be a BoxLang object, structure, or a Map or function.clasz
- The interface to create the dynamic proxy- Returns:
- An implementation of the interface using functions compiled in the interpreter
-