output_ScriptBinding.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. ConsoleFunctionGroupBegin( Output, "Functions to output to the console." );
  23. /*! @addtogroup ConsoleOutput Console Output
  24. @ingroup TorqueScriptFunctions
  25. @{
  26. */
  27. /*! Use the echo function to print messages to the console.
  28. @param text Any valid text string.
  29. @param ... Any additional valid text string(s).
  30. @return No return value.
  31. @sa error, warn
  32. */
  33. ConsoleFunctionWithDocs(echo, ConsoleVoid, 2, 0, ( text, [...]* ))
  34. {
  35. U32 len = 0;
  36. S32 i;
  37. for(i = 1; i < argc; i++)
  38. len += dStrlen(argv[i]);
  39. char *ret = Con::getReturnBuffer(len + 1);
  40. ret[0] = 0;
  41. for(i = 1; i < argc; i++)
  42. dStrcat(ret, argv[i]);
  43. Con::printf("%s", ret);
  44. ret[0] = 0;
  45. }
  46. /*! Prints a separator to the console.
  47. */
  48. ConsoleFunctionWithDocs(echoSeparator, ConsoleVoid, 0, 0, ())
  49. {
  50. Con::printSeparator();
  51. }
  52. /*! Use the warn function to print warning messages to the console. These messages usually yellow or orange.
  53. @param text Any valid text string.
  54. @param ... Any additional valid text string(s).
  55. @return No return value.
  56. @sa warn, error
  57. */
  58. ConsoleFunctionWithDocs(warn, ConsoleVoid, 2, 0, ( text, [...]* ))
  59. {
  60. U32 len = 0;
  61. S32 i;
  62. for(i = 1; i < argc; i++)
  63. len += dStrlen(argv[i]);
  64. char *ret = Con::getReturnBuffer(len + 1);
  65. ret[0] = 0;
  66. for(i = 1; i < argc; i++)
  67. dStrcat(ret, argv[i]);
  68. Con::warnf(ConsoleLogEntry::General, "%s", ret);
  69. ret[0] = 0;
  70. }
  71. /*! Use the error function to print error messages to the console. These messages usually print in red.
  72. @param text Any valid text string.
  73. @param ... Any additional valid text string(s).
  74. @return No return value.
  75. @sa echo, warn
  76. */
  77. ConsoleFunctionWithDocs(error, ConsoleVoid, 2, 0, ( text, [...]* ))
  78. {
  79. U32 len = 0;
  80. S32 i;
  81. for(i = 1; i < argc; i++)
  82. len += dStrlen(argv[i]);
  83. char *ret = Con::getReturnBuffer(len + 1);
  84. ret[0] = 0;
  85. for(i = 1; i < argc; i++)
  86. dStrcat(ret, argv[i]);
  87. Con::errorf(ConsoleLogEntry::General, "%s", ret);
  88. ret[0] = 0;
  89. }
  90. /*! Use the collapseEscape function to replace all escape sequences ('xx') with an expanded version ('xx').
  91. @param text A string, possibly containing escape sequences.
  92. @return Returns a copy of text with all escape sequences expanded.
  93. @sa collapseEscape
  94. */
  95. ConsoleFunctionWithDocs(expandEscape, ConsoleString, 2, 2, ( text ))
  96. {
  97. TORQUE_UNUSED( argc );
  98. char *ret = Con::getReturnBuffer(dStrlen(argv[1])*2 + 1); // worst case situation
  99. expandEscape(ret, argv[1]);
  100. return ret;
  101. }
  102. /*! Use the collapseEscape function to replace all escape sequences ('xx') with a collapsed version ('xx').
  103. @param text A string, possibly containing escape sequences.
  104. @return Returns a copy of text with all escape sequences converted to an encoding.
  105. @sa expandEscape
  106. */
  107. ConsoleFunctionWithDocs(collapseEscape, ConsoleString, 2, 2, ( text ))
  108. {
  109. TORQUE_UNUSED( argc );
  110. char *ret = Con::getReturnBuffer(dStrlen(argv[1]) + 1); // worst case situation
  111. dStrcpy( ret, argv[1] );
  112. collapseEscape( ret );
  113. return ret;
  114. }
  115. /*! Use the setLogMode function to set the logging level based on bits that are set in the mode argument.
  116. This is a general debug method and should be used in all but release cases and perhaps even then.
  117. @param mode A bitmask enabling various types of logging. See 'Logging Modes' table below.
  118. @return No return value.
  119. @sa intputLog
  120. */
  121. ConsoleFunctionWithDocs(setLogMode, ConsoleVoid, 2, 2, ( mode ))
  122. {
  123. TORQUE_UNUSED( argc );
  124. Con::setLogMode(dAtoi(argv[1]));
  125. }
  126. /*! Use the setEchoFileLoads function to enable/disable echoing of file loads (to console).
  127. This does not completely disable message, but rather adds additional methods when echoing is set to true. File loads will always echo a compile statement if compiling is required, and an exec statement at all times
  128. @param enable A boolean value. If this value is true, extra information will be dumped to the console when files are loaded.
  129. @return No return value.
  130. */
  131. ConsoleFunctionWithDocs(setEchoFileLoads, ConsoleVoid, 2, 2, ( enable ))
  132. {
  133. TORQUE_UNUSED( argc );
  134. ResourceManager->setFileNameEcho(dAtob(argv[1]));
  135. }
  136. //----------------------------------------------------------------
  137. /*! Use the quit function to stop the engine and quit to the command line.
  138. @return No return value
  139. */
  140. ConsoleFunctionWithDocs(quit, ConsoleVoid, 1, 1, ())
  141. {
  142. TORQUE_UNUSED( argc );
  143. TORQUE_UNUSED( argv );
  144. Platform::postQuitMessage(0);
  145. }
  146. /*! quitWithErrorMessage(msg)
  147. - Quit, showing the provided error message. This is equivalent
  148. to an AssertISV.
  149. @param Error Message
  150. @return No return value
  151. */
  152. ConsoleFunctionWithDocs(quitWithErrorMessage, ConsoleVoid, 2, 2, (msg string))
  153. {
  154. AssertISV(false, argv[1]);
  155. }
  156. //----------------------------------------------------------------
  157. /*! Open a URL in the user's favorite web browser.
  158. */
  159. ConsoleFunctionWithDocs( gotoWebPage, ConsoleVoid, 2, 2, ( address ))
  160. {
  161. TORQUE_UNUSED( argc );
  162. const char* protocolSep = dStrstr(argv[1],"://");
  163. if( protocolSep != NULL )
  164. {
  165. Platform::openWebBrowser(argv[1]);
  166. return;
  167. }
  168. // if we don't see a protocol seperator, then we know that some bullethead
  169. // sent us a bad url. We'll first check to see if a file inside the sandbox
  170. // with that name exists, then we'll just glom "http://" onto the front of
  171. // the bogus url, and hope for the best.
  172. char urlBuf[2048];
  173. if(Platform::isFile(argv[1]) || Platform::isDirectory(argv[1]))
  174. {
  175. dSprintf(urlBuf, sizeof(urlBuf), "file://%s",argv[1]);
  176. }
  177. else
  178. dSprintf(urlBuf, sizeof(urlBuf), "http://%s",argv[1]);
  179. Platform::openWebBrowser(urlBuf);
  180. return;
  181. }
  182. //----------------------------------------------------------------
  183. /*! Use the cls function to clear the console output.
  184. @return No return value
  185. */
  186. ConsoleFunctionWithDocs( cls, ConsoleVoid, 1, 1, ())
  187. {
  188. Con::cls();
  189. };
  190. //----------------------------------------------------------------
  191. ConsoleFunctionGroupEnd(Output)
  192. /*! @} */ // group ConsoleOutput