/** * Caches a block of code, returning a handle that can be passed to runCachedBlock(). * * @param id An identifier. If null, a unique identifier is generated * @param code The code * @param namespace If true, the namespace will be set * @return Description of the Return Value * @exception Exception instances are thrown when various BeanShell errors occur * @since jEdit 4.1pre1 */ public BshMethod cacheBlock(String id, String code, boolean namespace) throws Exception { String name = "__internal_" + id; // evaluate a method declaration if (namespace) { _eval(global, name + "(ns) {\nthis.callstack.set(0,ns);\n" + code + "\n}"); return global.getMethod(name, new Class[] {NameSpace.class}); } else { _eval(global, name + "() {\n" + code + "\n}"); return global.getMethod(name, new Class[0]); } } // }}}