moduleDefinition_ScriptBinding.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. #include "console/engineAPI.h"
  23. #include "moduleDefinition.h"
  24. #include "moduleManager.h"
  25. DefineEngineMethod(ModuleDefinition, save, bool, (),,
  26. "Saves the module definition to the file it was loaded from (if any).\n"
  27. "@return (bool success) Whether the module definition was saved or not.\n")
  28. {
  29. // Save.
  30. return object->save();
  31. }
  32. //-----------------------------------------------------------------------------
  33. DefineEngineMethod(ModuleDefinition, getModuleManager, S32, (),,
  34. "Gets the module manager which this module definition is registered with (if any).\n"
  35. "@return (moduleManager) The module manager which this module definition is registered with (zero if not registered).\n")
  36. {
  37. // Fetch module manager.
  38. ModuleManager* pModuleManager = object->getModuleManager();
  39. return pModuleManager != NULL ? pModuleManager->getId() : 0;
  40. }
  41. //-----------------------------------------------------------------------------
  42. DefineEngineMethod(ModuleDefinition, getDependencyCount, S32, (), ,
  43. "Gets the number of module dependencies this module definition has.\n"
  44. "@return (int count) The number of module dependencies this module definition has.\n")
  45. {
  46. // Get module dependency count.
  47. return object->getDependencyCount();
  48. }
  49. //-----------------------------------------------------------------------------
  50. DefineEngineMethod(ModuleDefinition, getDependency, String, (U32 dependencyIndex), (0),
  51. "Gets the module dependency at the specified index.\n"
  52. "@param dependencyIndex The module dependency index.\n"
  53. "@return (module - dependency) The module dependency at the specified index.")
  54. {
  55. // Get module dependency.
  56. ModuleDefinition::ModuleDependency dependency;
  57. if ( object->getDependency( dependencyIndex, dependency ) == false )
  58. return StringTable->EmptyString();
  59. // Format module dependency.
  60. char* pReturnBuffer = Con::getReturnBuffer( 256 );
  61. dSprintf( pReturnBuffer, 256, "%s %d", dependency.mModuleId, dependency.mVersionId );
  62. return pReturnBuffer;
  63. }
  64. //-----------------------------------------------------------------------------
  65. DefineEngineMethod(ModuleDefinition, addDependency, bool, (const char* pModuleId, U32 versionId), ("", 0),
  66. "Adds the specified moduleId and vesionId as a dependency.\n"
  67. "@param moduleId The module Id to add as a dependency.\n"
  68. "@param versionId The version Id to add as a dependency. Using zero indicates any version."
  69. "@return (bool success) Whether the module dependency was added or not.")
  70. {
  71. // Add dependency.
  72. return object->addDependency( pModuleId, versionId );
  73. }
  74. //-----------------------------------------------------------------------------
  75. DefineEngineMethod(ModuleDefinition, removeDependency, bool, (const char* pModuleId), (""),
  76. "Removes the specified moduleId as a dependency.\n"
  77. "@param moduleId The module Id to remove as a dependency.\n"
  78. "@return (bool success) Whether the module dependency was removed or not.")
  79. {
  80. // Remove dependency.
  81. return object->removeDependency( pModuleId );
  82. }