expando_ScriptBinding.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. /*! @defgroup PathExpandoFunctions Path Expando
  22. @ingroup TorqueScriptFunctions
  23. @{
  24. */
  25. /*! Expands an expando or relative path into a full path.
  26. */
  27. ConsoleFunctionWithDocs(expandPath, ConsoleString, 2, 2, (string path))
  28. {
  29. char* ret = Con::getReturnBuffer( 1024 );
  30. Con::expandPath(ret, 1024, argv[1]);
  31. return ret;
  32. }
  33. //-----------------------------------------------------------------------------
  34. /*! Collapses a path into either an expando path or a relative path.
  35. */
  36. ConsoleFunctionWithDocs(collapsePath, ConsoleString, 2, 2, (string path))
  37. {
  38. char* ret = Con::getReturnBuffer( 1024 );
  39. Con::collapsePath(ret, 1024, argv[1]);
  40. return ret;
  41. }
  42. //-----------------------------------------------------------------------------
  43. /*! Adds the expando to the path. If it already exists then it is replaced.
  44. */
  45. ConsoleFunctionWithDocs(addPathExpando, ConsoleVoid, 3, 3, (string expando, string path))
  46. {
  47. Con::addPathExpando(argv[1], argv[2]);
  48. }
  49. //-----------------------------------------------------------------------------
  50. /*! Removes the specified path expando.
  51. */
  52. ConsoleFunctionWithDocs(removePathExpando, ConsoleVoid, 2, 2, (string expando))
  53. {
  54. Con::removePathExpando(argv[1]);
  55. }
  56. //-----------------------------------------------------------------------------
  57. /*! Checks whether the specified path expando is current set or not.
  58. */
  59. ConsoleFunctionWithDocs(isPathExpando, ConsoleBool, 2, 2, (string expando))
  60. {
  61. return Con::isPathExpando(argv[1]);
  62. }
  63. //-----------------------------------------------------------------------------
  64. /*! Gets the expando path count.
  65. */
  66. ConsoleFunctionWithDocs(getPathExpandoCount, ConsoleInt, 1, 1, ())
  67. {
  68. return Con::getPathExpandoCount();
  69. }
  70. //-----------------------------------------------------------------------------
  71. /*! Gets the path expando key (the expando name) at the specified index.
  72. */
  73. ConsoleFunctionWithDocs(getPathExpandoKey, ConsoleString, 2, 2, (int expandoIndex))
  74. {
  75. // Fetch expando index.
  76. const S32 expandoIndex = dAtoi(argv[1]);
  77. // Is the expando index in range?
  78. if ( expandoIndex < 0 || expandoIndex >= (S32) Con::getPathExpandoCount() )
  79. {
  80. // No, so warn.
  81. Con::warnf("getPathExpandoKey() - Expando index of '%d' is out of bounds. Current expando count is '%d'.",
  82. expandoIndex,
  83. Con::getPathExpandoCount() );
  84. return StringTable->EmptyString;
  85. }
  86. // Fetch path expando key.
  87. return Con::getPathExpandoKey( expandoIndex );
  88. }
  89. //-----------------------------------------------------------------------------
  90. /*! Gets the path expando value (the expando path) at the specified index.
  91. */
  92. ConsoleFunctionWithDocs(getPathExpandoValue, ConsoleString, 2, 2, (int expandoIndex))
  93. {
  94. // Fetch expando index.
  95. const S32 expandoIndex = dAtoi(argv[1]);
  96. // Is the expando index in range?
  97. if ( expandoIndex < 0 || expandoIndex >= (S32) Con::getPathExpandoCount() )
  98. {
  99. // No, so warn.
  100. Con::warnf("getPathExpandoValue() - Expando index of '%d' is out of bounds. Current expando count is '%d'.",
  101. expandoIndex,
  102. Con::getPathExpandoCount() );
  103. return StringTable->EmptyString;
  104. }
  105. // Fetch path expando value.
  106. return Con::getPathExpandoValue( expandoIndex );
  107. }
  108. /*! @} */ // group PathExpandoFunctions