JSBind.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #include <Atomic/Atomic.h>
  5. #include <Atomic/Core/ProcessUtils.h>
  6. #include <Atomic/Resource/ResourceCache.h>
  7. #include "JSBind.h"
  8. #include "JSBindings.h"
  9. #ifdef WIN32
  10. #include <Windows.h>
  11. #endif
  12. using namespace Atomic;
  13. SharedPtr<Context> JSBind::context_;
  14. SharedPtr<FileSystem> JSBind::fileSystem_;
  15. SharedPtr<Engine> JSBind::engine_;
  16. String JSBind::ROOT_FOLDER;
  17. String JSBind::PLATFORM;
  18. void JSBind::Initialize()
  19. {
  20. context_ = new Context();
  21. fileSystem_ = new FileSystem(context_);
  22. engine_ = new Engine(context_);
  23. }
  24. #include <stdio.h>
  25. void Run(const Vector<String>& arguments)
  26. {
  27. JSBind::Initialize();
  28. if (arguments.Size() < 1)
  29. {
  30. ErrorExit("Usage: JSBind absolute_path_to_atomic_runtime_source_tree [optional] platform");
  31. }
  32. JSBind::ROOT_FOLDER = arguments[0];
  33. if (arguments.Size() > 1)
  34. JSBind::PLATFORM = arguments[1];
  35. if (JSBind::PLATFORM.Length() && JSBind::PLATFORM != "WEB")
  36. ErrorExit("Platform argument only supports WEB at this time");
  37. if (!JSBind::fileSystem_->DirExists(JSBind::ROOT_FOLDER + "/Source/Tools/JSBind"))
  38. {
  39. ErrorExit("The given Atomic Runtime source tree is invalid");
  40. }
  41. VariantMap engineParameters;
  42. engineParameters["Headless"] = true;
  43. engineParameters["WorkerThreads"] = false;
  44. engineParameters["LogName"] = String::EMPTY;
  45. JSBind::engine_->Initialize(engineParameters);
  46. ResourceCache* cache = JSBind::context_->GetSubsystem<ResourceCache>();
  47. cache->AddResourceDir(JSBind::ROOT_FOLDER + "/Source/Tools/JSBind");
  48. JSBindings* bindings = new JSBindings();
  49. bindings->Initialize();
  50. bindings->ParseHeaders();
  51. }
  52. int main(int argc, char** argv)
  53. {
  54. Vector<String> arguments;
  55. arguments = ParseArguments(argc, argv);
  56. Run(arguments);
  57. return 0;
  58. }