public interface InterpreterHook
To implement a hook the class should implement this interface. It is
recommended to extend the class SimpleHook
instead of implementing a fresh class just implementing this interface. There
are a lot of methods in this interface and usually a hook class need
functionality only for a subset. The class SimpleHook
gives default implementation for the
methods and eases hook development providing extended methods.
To make a hook class used by the interpreter the class should be on the
classpath during runtime and the configuration key hook.
N
should contains the FQN of the implementing class. The configuration
parameter N should run from 0 ... and the hooks will be registered in
the order they are numbered and executed in backward order. To use the hook
delivered with jScriptBasic you should configure:
hook.0=com.scriptbasic.hooks.RunLimitHookto have this hook called last (registered first). There are no hooks registered automatically.
The hooks are in a chain and every hook method should call the same hook method on the next hook object on the chain. The hooks are chained backward. The last hook will be called directly by the interpreter and that hook will call the previous and so on. Thus the first hook registered is called last and the last registered will be called first.
A hook method can decide for some good reason to break the chain not invoking the next element in the chain.
Modifier and Type | Method and Description |
---|---|
Object |
afterCallJavaFunction(Method method,
Object result)
This method is called when the interpreter was calling a Java static
method.
|
void |
afterExecute(Command command)
This method is called after the interpreter executed a command.
|
void |
afterPop(Command command) |
void |
afterPush(Command command) |
void |
beforeCallJavaFunction(Method method) |
void |
beforeExecute(Command command)
This method is called before the interpreter executes a command.
|
void |
beforePop() |
void |
beforePush(Command command) |
void |
beforeRegisteringJavaMethod(String alias,
Class<?> klass,
String methodName,
Class<?>[] argumentTypes)
This method is called before registering a java method into the
interpreter.
|
void |
beforeSubroutineCall(String subroutineName,
LeftValueList arguments,
RightValue[] argumentValues)
This method is called before the interpreter invokes a subroutine.
|
void |
init()
This method is called at the end of the hook registering.
|
void |
setInterpreter(ExtendedInterpreter interpreter)
During registration the interpreter calls this method to make the
interpreter accessible for the hook objects.
|
void |
setNext(InterpreterHook next)
When a hook is registered the registering process calls this method and
passes the next element in the hook chain.
|
void |
setReturnValue(RightValue returnValue)
This method is called after a subroutine has set its return value.
|
RightValue |
variableRead(String variableName,
RightValue value)
This hook is called when the interpreter accesses a variable.
|
void init()
void setNext(InterpreterHook next)
next
- the next element in the chain.void setInterpreter(ExtendedInterpreter interpreter)
interpreter
- void beforeExecute(Command command)
command
- the command object to be executedvoid afterExecute(Command command)
command
- the command just executed.void beforeRegisteringJavaMethod(String alias, Class<?> klass, String methodName, Class<?>[] argumentTypes)
alias
- the name of the function as it will be known to the BASIC
program.klass
- the Java class where the static method is.methodName
- the Java name of the methodargumentTypes
- the argument types of the methods. This, together with the
name of the method and the class identifies the actual method
that will be available to the BASIC programs to be called
through the name alias
.void beforePush(Command command)
command
- void afterPush(Command command)
command
- void beforePop()
void afterPop(Command command)
command
- void setReturnValue(RightValue returnValue)
ExtendedInterpreter.disableHook()
and ExtendedInterpreter.enableHook()
.returnValue
- ExtendedInterpreter.disableHook()
void beforeSubroutineCall(String subroutineName, LeftValueList arguments, RightValue[] argumentValues)
subroutineName
- the symbolic name of the subroutinearguments
- the argument left valuesargumentValues
- the argument evaluated values that were assigned to the local
variable table to the argumentsvoid beforeCallJavaFunction(Method method)
method
- Object afterCallJavaFunction(Method method, Object result)
method
- the method that was calledresult
- the result that the static method returnedRightValue variableRead(String variableName, RightValue value)
variableName
- the name of the variablevalue
- the value of the variable when accessedCopyright © 2013 Verhas and Verhas Software Craftsmen. All Rights Reserved.