Added cleanup and reset methods to ScriptingCore.

Re-filed #2017 without ``externalScriptPath`` functionality. See details in #2017.