ScriptEngine.eval()call and call the same in subsequent
ScriptEngine.eval()calls. This is because internally, each
evaled code is compiled as a separate ScriptXXX class. i.e., all global functions in the
evaled code go into a class derived from Script class. To give an illusion of single engine level scope for "global" functions, we create a map of method closures from all ScriptXXX instances created and search there for global functions (using Groovy's MetaClass mechanism). With this change, the engine behaves as if there is a single global functions scope per
ScriptEngineinstance. Groovy's Meta Object Protocol (MOP) is really powerful indeed.