PageRenderTime 32ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre3/bsh/commands/run.bsh

#
Unknown | 36 lines | 31 code | 5 blank | 0 comment | 0 complexity | e4b3241355ed12648f578b05a95bd51b MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. bsh.help.run= "usage: Thread run( filename )";
  2. /**
  3. Run a command in its own in its own private global namespace and interpeter
  4. context. (kind of like the unix "chroot" for the namespace)
  5. The root bsh system object is extended (with the extend() command) and
  6. made visible here, so that system info is effectively inherited.
  7. Because the root bsh object is extended it is effectively read / copy
  8. on write... e.g. you can change directories in the child context, do
  9. imports, etc. and it will not affect the calling context.
  10. @return Returns the context so that you can gather results.
  11. @param runArgument an argument passed to the child context under the
  12. name runArgument. e.g. you might pass in the calling This context
  13. from which to draw variables, etc.
  14. */
  15. run( String filename, Object runArgument )
  16. {
  17. // Our local namespace is going to be the new root (global)
  18. // make local copies of the system stuff.
  19. //
  20. // Extend the root system object
  21. // this is problematic... probably need more here...
  22. bsh=extend(global.bsh);
  23. bsh.help=extend(bsh.help);
  24. // cut us off... make us the root (global) namespace for this command
  25. this.namespace.prune();
  26. this.interpreter.source( filename, this.namespace );
  27. return this;
  28. }
  29. run( String filename ) {
  30. run( filename, null );
  31. }