Context
Context represents an internal state in Pnuts runtime environment. A Context
object contains the following information.
- Stack frame (in pure interpreter only)
- Which Pnuts-package being used
- Imported Java-package list
- OutputStream to which print() write data
- OutputStream to which error() write message
- OutputStream to which the prompt and the results are written
- ClassLoader by which load() find a script
- A PnutsImpl object
- User defined variables
A pnuts.lang.Context object represents a context. See "Pnuts API Overview" for details.
getContext() refers to the currently executing context, which is created when an interactive session starts. All other executions refer to the current context.
When context is specified to the parameter of these functions, a clone of the context is created and the script is executed with the clone.
When context is not specified, a clone of the current context is created and the script is executed with the clone. In this case, the import() state and the current package are reset to the default values.
Where user message is shown
For each context the following can be specified.
- Standard output
- Error output
- Where result of evaluation is printed
- context . setOutputStream
(OutputStream anOutputStream) or (Writer aWriter )
- context . setErrorStream
(OutputStream aOutputStream) or (Writer aWriter )
- context . setTerminalStream
(OutputStream anOutputStream) or (Writer aWriter )
- context . getOutputStream ()
- context . getErrorStream ()
- context . getTerminalStream ()
|
User Defined Variables
- context . set ( String key , Object value )
- context . get ( String key )
- context . keys ( )
|
User defined variables are environment variables assiciated with a context.
It is shared among the context's clones.
Class Loader
- setClassLoader ( ClassLoader loader )
- getClassLoader ( )
|
A class loader can be associated with the context. It is used to resolve class names, and finds scripts when load() function is used.
It is shared among the context's clones.
PnutsImpl Object
- context . setPnutsImpl ( PnutsImpl impl )
- context . getPnutsImpl ( )
|
See "On-the-fly Compiler and Pure Interpreter".