AEJavascript.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #pragma once
  5. #include <Atomic/Core/Object.h>
  6. #include <Duktape/duktape.h>
  7. using namespace Atomic;
  8. namespace AtomicEditor
  9. {
  10. class JSErrorChecker;
  11. struct JSError
  12. {
  13. String fullpath;
  14. String message;
  15. int line;
  16. int column;
  17. int tokenPos;
  18. };
  19. // This is the Javascript subsystem for the editor
  20. // the embedded player uses a separate VM
  21. class AEJavascript : public Object
  22. {
  23. OBJECT(AEJavascript);
  24. public:
  25. /// Construct.
  26. AEJavascript(Context* context);
  27. /// Destruct.
  28. ~AEJavascript();
  29. bool ExecuteFile(const String& path);
  30. bool ParseJavascriptToJSON(const char* source, String& json, bool loose = true);
  31. bool BeautifyJavascript(const char* source, String& output);
  32. bool CheckJSErrors(bool fullCheck = false);
  33. const Vector<JSError>& GetJSErrors() { return errors_; }
  34. private:
  35. bool ReadZeroTerminatedSourceFile(const String& path, String& source);
  36. void HandleFileChanged(StringHash eventType, VariantMap& eventData);
  37. void HandleEditorShutdown(StringHash eventType, VariantMap& eventData);
  38. static int js_module_search(duk_context* ctx);
  39. static int js_read_source(duk_context* ctx);
  40. duk_context* ctx_;
  41. Vector<JSError> errors_;
  42. SharedPtr<JSErrorChecker> errorChecker_;
  43. // for access within duktape callbacks
  44. static WeakPtr<AEJavascript> instance_;
  45. Vector<String> modifiedJS_;
  46. };
  47. }