Context

Context is an internal state in Pnuts runtime environment, which is represented by pnuts.lang.Context class. A context has the following information:

See "Pnuts API Overview" for the overview of the class.

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.

OutputStream for Messages

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 ()

Context-local Variables

context . set ( String key , Object value )
context . get ( String key )
context . keys ( )

Context-local variables are environment variables assiciated with a context.

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