Script.cpp 764 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "Script.h"
  2. #include "ScriptController.h"
  3. namespace gameplay
  4. {
  5. Script::Script() : _scope(GLOBAL), _env(0)
  6. {
  7. }
  8. Script::~Script()
  9. {
  10. Game::getInstance()->getScriptController()->unloadScript(this);
  11. }
  12. const char* Script::getPath() const
  13. {
  14. return _path.c_str();
  15. }
  16. Script::Scope Script::getScope() const
  17. {
  18. return _scope;
  19. }
  20. bool Script::functionExists(const char* name) const
  21. {
  22. return Game::getInstance()->getScriptController()->functionExists(name, this);
  23. }
  24. bool Script::reload()
  25. {
  26. ScriptController* sc = Game::getInstance()->getScriptController();
  27. // First unload our current script
  28. sc->unloadScript(this);
  29. // Now attempt to reload the script
  30. return Game::getInstance()->getScriptController()->loadScript(this);
  31. }
  32. }