BsMonoManager.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #pragma once
  2. #include "BsMonoPrerequisites.h"
  3. #include "BsScriptMeta.h"
  4. #include "CmModule.h"
  5. #include <mono/jit/jit.h>
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief Loads Mono script assemblies and manages script objects.
  10. */
  11. class BS_MONO_EXPORT MonoManager : public CM::Module<MonoManager>
  12. {
  13. public:
  14. MonoManager();
  15. ~MonoManager();
  16. MonoAssembly& loadAssembly(const CM::String& path, const CM::String& name);
  17. void unloadAssembly(MonoAssembly& assembly);
  18. /**
  19. * @brief Searches all loaded assemblies for the specified class.
  20. */
  21. MonoClass* findClass(const CM::String& ns, const CM::String& typeName);
  22. /**
  23. * @brief Searches all loaded assemblies for the specified class.
  24. */
  25. MonoClass* findClass(::MonoClass* rawMonoClass);
  26. /**
  27. * @brief Returns the type name of the provided object, with namespace.
  28. *
  29. * @param obj If non-null, the object to get the type name of.
  30. */
  31. CM::String getFullTypeName(MonoObject* obj);
  32. /**
  33. * @brief Returns the namespace of the provided object.
  34. *
  35. * @param obj If non-null, the object to get the namespace of.
  36. */
  37. CM::String getNamespace(MonoObject* obj);
  38. /**
  39. * @brief Returns the type name of the provided object, without namespace.
  40. *
  41. * @param obj If non-null, the object to get the type name of.
  42. */
  43. CM::String getTypeName(MonoObject* obj);
  44. MonoDomain* getDomain() const { return mDomain; }
  45. MonoAssembly* getAssembly(const CM::String& name) const;
  46. static void registerScriptType(ScriptMeta* metaData);
  47. private:
  48. static const CM::String MONO_LIB_DIR;
  49. static const CM::String MONO_ETC_DIR;
  50. static CM::UnorderedMap<CM::String, CM::Vector<ScriptMeta*>::type>::type& getTypesToInitialize()
  51. {
  52. static CM::UnorderedMap<CM::String, CM::Vector<ScriptMeta*>::type>::type mTypesToInitialize;
  53. return mTypesToInitialize;
  54. }
  55. CM::UnorderedMap<CM::String, MonoAssembly*>::type mAssemblies;
  56. MonoDomain* mDomain;
  57. bool mIsCoreLoaded;
  58. };
  59. }