Context

Context represents an internal state in Pnuts runtime environment. A Context object contains the following information.

A pnuts.lang.Context object represents a context. See "Pnuts API Overview" for details.

getContext()

getContext() refers to the currently executing context, which is created when an interactive session starts. All other executions refer to the current context.

eval ( String expression {, Context context } )
load ( String scriptFile {, Context context } )
loadFile ( String scriptFile {, Context 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.

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".


Back