PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/bsh/commands/run.bsh

#
Unknown | 50 lines | 43 code | 7 blank | 0 comment | 0 complexity | 48436b0c1cead04c7124f9463dd8baf3 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. /**
  2. Run a command in its own in its own private global namespace and interpeter
  3. context. (kind of like the unix "chroot" for the namespace)
  4. The root bsh system object is extended (with the extend() command) and
  5. made visible here, so that system info is effectively inherited.
  6. Because the root bsh object is extended it is effectively read / copy
  7. on write... e.g. you can change directories in the child context, do
  8. imports, etc. and it will not affect the calling context.
  9. <p>
  10. run() is like source() except that it runs the command in a new,
  11. subordinate and prune()'d namespace. So it's like "running" a command
  12. instead of "sourcing" it. Returns the object context in which the command
  13. was run.
  14. <p>
  15. Returns the context so that you can gather results.
  16. <p>
  17. Paramameter runArgument an argument passed to the child context under the
  18. name runArgument. e.g. you might pass in the calling This context
  19. from which to draw variables, etc.
  20. <p>
  21. @return Returns the context so that you can gather results.
  22. @param runArgument an argument passed to the child context under the
  23. name runArgument. e.g. you might pass in the calling This context
  24. from which to draw variables, etc.
  25. */
  26. bsh.help.run= "usage: Thread run( filename )";
  27. run( String filename, Object runArgument )
  28. {
  29. // Our local namespace is going to be the new root (global)
  30. // make local copies of the system stuff.
  31. //
  32. // Extend the root system object
  33. // this is problematic... probably need more here...
  34. bsh=extend(global.bsh);
  35. bsh.help=extend(bsh.help);
  36. // cut us off... make us the root (global) namespace for this command
  37. this.namespace.prune();
  38. this.interpreter.source( filename, this.namespace );
  39. return this;
  40. }
  41. run( String filename ) {
  42. run( filename, null );
  43. }