ScriptEngine.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #ifndef SCRIPT_SCRIPTENGINE_H
  24. #define SCRIPT_SCRIPTENGINE_H
  25. #include "RefCount.h"
  26. class asIScriptEngine;
  27. class asIScriptContext;
  28. struct asSMessageInfo;
  29. //! Script engine logging mode
  30. enum ScriptLogMode
  31. {
  32. LOGMODE_IMMEDIATE = 0,
  33. LOGMODE_RETAINED
  34. };
  35. //! Maximum function/method nesting level
  36. static const unsigned MAX_SCRIPT_NESTING_LEVEL = 32;
  37. //! Utilizes the AngelScript library for executing scripts
  38. class ScriptEngine : public RefCounted
  39. {
  40. public:
  41. //! Construct. Create the AngelScript engine and register string & array classes
  42. ScriptEngine();
  43. //! Destruct. Release the AngelScript engine
  44. ~ScriptEngine();
  45. //! Compile and execute a line of script
  46. bool execute(const std::string& line);
  47. //! Perform garbage collection
  48. void garbageCollect(bool fullCycle);
  49. //! Set script engine logging mode, immediate is default
  50. void setLogMode(ScriptLogMode mode);
  51. //! Clear retained mode log messages
  52. void clearLogMessages();
  53. //! Log a message from the script engine
  54. void logMessage(const asSMessageInfo* msg);
  55. //! Return the AngelScript engine
  56. asIScriptEngine* getAngelScriptEngine() const { return mAngelScriptEngine; }
  57. //! Return immediate execution script context
  58. asIScriptContext* getImmediateContext() const { return mImmediateContext; }
  59. //! Return a script function/method execution context
  60. asIScriptContext* getScriptFileContext(unsigned nestingLevel) const;
  61. //! Return logging mode
  62. ScriptLogMode getLogMode() const { return mLogMode; }
  63. //! Return retained mode log messages
  64. const std::string& getLogMessages() const { return mLogMessages; }
  65. private:
  66. //! AngelScript engine
  67. asIScriptEngine* mAngelScriptEngine;
  68. //! Immediate execution script context
  69. asIScriptContext* mImmediateContext;
  70. //! Script function/method execution contexts
  71. std::vector<asIScriptContext*> mScriptFileContexts;
  72. //! Script engine logging mode
  73. ScriptLogMode mLogMode;
  74. //! Retained mode log messages
  75. std::string mLogMessages;
  76. };
  77. #endif // SCRIPT_SCRIPTENGINE_H