moduleDefinition_ScriptBinding.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. ConsoleMethod(ModuleDefinition, save, bool, 2, 2, "() - Saves the module definition to the file it was loaded from (if any).\n"
  23. "@return (bool success) Whether the module definition was saved or not.")
  24. {
  25. // Save.
  26. return object->save();
  27. }
  28. //-----------------------------------------------------------------------------
  29. ConsoleMethod(ModuleDefinition, getModuleManager, S32, 2, 2, "() - Gets the module manager which this module definition is registered with (if any).\n"
  30. "@return (moduleManager) The module manager which this module definition is registered with (zero if not registered).")
  31. {
  32. // Fetch module manager.
  33. ModuleManager* pModuleManager = object->getModuleManager();
  34. return pModuleManager != NULL ? pModuleManager->getId() : 0;
  35. }
  36. //-----------------------------------------------------------------------------
  37. ConsoleMethod(ModuleDefinition, getDependencyCount, S32, 2, 2, "() - Gets the number of module dependencies this module definition has.\n"
  38. "@return (int count) The number of module dependencies this module definition has.")
  39. {
  40. // Get module dependency count.
  41. return object->getDependencyCount();
  42. }
  43. //-----------------------------------------------------------------------------
  44. ConsoleMethod(ModuleDefinition, getDependency, const char*, 3, 3, "(int dependencyIndex) - Gets the module dependency at the specified index.\n"
  45. "@param dependencyIndex The module dependency index.\n"
  46. "@return (module-dependency) The module dependency at the specified index.")
  47. {
  48. // Fetch dependency index.
  49. const U32 dependencyIndex = (U32)dAtoi(argv[2]);
  50. // Get module dependency.
  51. ModuleDefinition::ModuleDependency dependency;
  52. if ( object->getDependency( dependencyIndex, dependency ) == false )
  53. return StringTable->EmptyString;
  54. // Format module dependency.
  55. char* pReturnBuffer = Con::getReturnBuffer( 256 );
  56. dSprintf( pReturnBuffer, 256, "%s %d", dependency.mModuleId, dependency.mVersionId );
  57. return pReturnBuffer;
  58. }
  59. //-----------------------------------------------------------------------------
  60. ConsoleMethod(ModuleDefinition, addDependency, bool, 4, 4, "(moduleId, versionId) - Adds the specified moduleId and vesionId as a dependency.\n"
  61. "@param moduleId The module Id to add as a dependency.\n"
  62. "@param versionId The version Id to add as a dependency. Using zero indicates any version.\n"
  63. "@return (bool success) Whether the module dependency was added or not.")
  64. {
  65. // Fetch module Id.
  66. const char* pModuleId = argv[2];
  67. // Fetch version Id.
  68. const U32 versionId = (U32)dAtoi(argv[3]);
  69. // Add dependency.
  70. return object->addDependency( pModuleId, versionId );
  71. }
  72. //-----------------------------------------------------------------------------
  73. ConsoleMethod(ModuleDefinition, removeDependency, bool, 3, 3, "(moduleId) - Removes the specified moduleId as a dependency.\n"
  74. "@param moduleId The module Id to remove as a dependency.\n"
  75. "@return (bool success) Whether the module dependency was removed or not.")
  76. {
  77. // Fetch module Id.
  78. const char* pModuleId = argv[2];
  79. // Remove dependency.
  80. return object->removeDependency( pModuleId );
  81. }