streamObject_ScriptBinding.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. ConsoleMethodGroupBeginWithDocs(StreamObject, SimObject)
  23. /*! Gets the current status of the StreamObject
  24. @return The current status as a string (Ok, IOError, EOS, IllegalCall, Closed, UnknownError, Invalid)
  25. */
  26. ConsoleMethodWithDocs(StreamObject, getStatus, const char *, 2, 2, ())
  27. {
  28. return object->getStatus();
  29. }
  30. /*! Test for end of stream
  31. @return Returns true if at the end of the stream, false otherwise.
  32. */
  33. ConsoleMethodWithDocs(StreamObject, isEOS, ConsoleBool, 2, 2, ())
  34. {
  35. return object->isEOS();
  36. }
  37. /*! Test for end of file stream (identical to isEOS()
  38. @return Returns true if at the end of the stream, false otherwise.
  39. @sa isEOS
  40. */
  41. ConsoleMethodWithDocs(StreamObject, isEOF, ConsoleBool, 2, 2, ())
  42. {
  43. return object->isEOS();
  44. }
  45. //////////////////////////////////////////////////////////////////////////
  46. /*!
  47. @return Returns the current position in the stream as an integer or zero if failed
  48. */
  49. ConsoleMethodWithDocs(StreamObject, getPosition, ConsoleInt, 2, 2, ())
  50. {
  51. return object->getPosition();
  52. }
  53. /*! Resets the current stream position
  54. @param The desired index
  55. @return Returns true if succeeded, flase otherwise
  56. */
  57. ConsoleMethodWithDocs(StreamObject, setPosition, ConsoleBool, 3, 3, (newPosition))
  58. {
  59. return object->setPosition(dAtoi(argv[2]));
  60. }
  61. /*! Get the size of the stream
  62. @return The size of the stream as an integer
  63. */
  64. ConsoleMethodWithDocs(StreamObject, getStreamSize, ConsoleInt, 2, 2, ())
  65. {
  66. return object->getStreamSize();
  67. }
  68. //////////////////////////////////////////////////////////////////////////
  69. /*! Read the stream until '\' or EOS
  70. @return A string containing the read line or an empty string if failed
  71. */
  72. ConsoleMethodWithDocs(StreamObject, readLine, const char *, 2, 2, ())
  73. {
  74. const char *str = object->readLine();
  75. return str ? str : "";
  76. }
  77. /*! Writes a line of text to the stream buffer
  78. @param The line to write
  79. @return No return value.
  80. */
  81. ConsoleMethodWithDocs(StreamObject, writeLine, ConsoleVoid, 3, 3, (line))
  82. {
  83. object->writeLine((U8 *)argv[2]);
  84. }
  85. //////////////////////////////////////////////////////////////////////////
  86. /*! Read a String and insert it into a StringTable
  87. @param caseSensitive A boolean representing whether the parser should ignore case or not (default false)
  88. @return Returns the string, or empty string if failed
  89. */
  90. ConsoleMethodWithDocs(StreamObject, readSTString, const char *, 2, 3, ([caseSensitive = false]))
  91. {
  92. const char *str = object->readSTString(argc > 2 ? dAtob(argv[2]) : false);
  93. return str ? str : "";
  94. }
  95. /*! Reads a string from a stream buffer
  96. @return The string or an empty string if failed.
  97. */
  98. ConsoleMethodWithDocs(StreamObject, readString, const char *, 2, 2, ())
  99. {
  100. const char *str = object->readString();
  101. return str ? str : "";
  102. }
  103. /*! Reads a string of provided length from the stream buffer.
  104. @param The maximum length to read in
  105. @return The requested string
  106. */
  107. ConsoleMethodWithDocs(StreamObject, readLongString, const char *, 3, 3, (maxLength))
  108. {
  109. const char *str = object->readLongString(dAtoi(argv[2]));
  110. return str ? str : "";
  111. }
  112. /*! Writes a string to buffer or provided length
  113. @param maxLength The maximum length to write
  114. @param string The string to write
  115. @return No return value
  116. */
  117. ConsoleMethodWithDocs(StreamObject, writeLongString, ConsoleVoid, 4, 4, (maxLength, string))
  118. {
  119. object->writeLongString(dAtoi(argv[2]), argv[3]);
  120. }
  121. /*! Write a string to the stream buffer
  122. @param string The string to write
  123. @param maxLength The maximum length to write (default 255).
  124. @return No return value.
  125. */
  126. ConsoleMethodWithDocs(StreamObject, writeString, ConsoleVoid, 3, 4, (string, [maxLength = 255]))
  127. {
  128. object->writeString(argv[2], argc > 3 ? dAtoi(argv[3]) : 255);
  129. }
  130. //////////////////////////////////////////////////////////////////////////
  131. /*! Copies stream contents from current position
  132. @param other The StreamObject from which to copy
  133. @return Returns true on success, and false otherwise.
  134. */
  135. ConsoleMethodWithDocs(StreamObject, copyFrom, ConsoleBool, 3, 3, (StreamObject other))
  136. {
  137. StreamObject *other = dynamic_cast<StreamObject *>(Sim::findObject(argv[2]));
  138. if(other == NULL)
  139. return false;
  140. return object->copyFrom(other);
  141. }
  142. ConsoleMethodGroupEndWithDocs(StreamObject)