fileObject_ScriptBinding.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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(FileObject, SimObject)
  23. /*! Use the openForRead method to open a previously created file for reading.
  24. @param filename The path and filename of the file to open for reading.
  25. @return Returns true if the file was successfully opened for reading, false otherwise.
  26. @sa close, OpenForAppend, OpenForWrite
  27. */
  28. ConsoleMethodWithDocs( FileObject, openForRead, ConsoleBool, 3, 3, ( filename ))
  29. {
  30. return object->readMemory(argv[2]);
  31. }
  32. /*! Use the openForWrite method to previously created or a new file for writing. In either case, the file will be overwritten.
  33. @param filename The path and filename of the file to open for writing.
  34. @return Returns true if the file was successfully opened for writing, false otherwise.
  35. @sa close, OpenForAppend, openForRead
  36. */
  37. ConsoleMethodWithDocs( FileObject, openForWrite, ConsoleBool, 3, 3, ( filename ))
  38. {
  39. return object->openForWrite(argv[2]);
  40. }
  41. /*! Use the openForAppend method to open a previously created file for appending. If the file specified by filename does not exist, the file is created first.
  42. @param filename The path and filename of the file to open for appending.
  43. @return Returns true if the file was successfully opened for appending, false otherwise.
  44. @sa close, openForRead, openForWrite
  45. */
  46. ConsoleMethodWithDocs( FileObject, openForAppend, ConsoleBool, 3, 3, ( filename ))
  47. {
  48. return object->openForWrite(argv[2], true);
  49. }
  50. /*! Use the isEOF method to check to see if the end of the current file (opened for read) has been reached.
  51. @return Returns true if the end of file has been reached, false otherwise.
  52. @sa openForRead
  53. */
  54. ConsoleMethodWithDocs( FileObject, isEOF, ConsoleBool, 2, 2, ())
  55. {
  56. return object->isEOF();
  57. }
  58. /*! Use the readLine method to read a single line from a file previously opened for reading.
  59. Use isEOF to check for end of file while reading.
  60. @return Returns the next line in the file, or a NULL string if the end-of-file has been reached.
  61. @sa isEOF, openForRead
  62. */
  63. ConsoleMethodWithDocs( FileObject, readLine, ConsoleString, 2, 2, ())
  64. {
  65. return (const char *) object->readLine();
  66. }
  67. /*! Read a line from the file without moving the stream position.
  68. */
  69. ConsoleMethodWithDocs( FileObject, peekLine, ConsoleString, 2, 2, ())
  70. {
  71. char *line = Con::getReturnBuffer( 512 );
  72. object->peekLine( (U8*)line, 512 );
  73. return line;
  74. }
  75. /*! Use the writeLine method to write a value ( text ) into a file that was previously opened for appending or over-writing.
  76. @param text The value to write to the file.
  77. @return No return value.
  78. @sa openForAppend, openForWrite
  79. */
  80. ConsoleMethodWithDocs( FileObject, writeLine, ConsoleVoid, 3, 3, ( text ))
  81. {
  82. object->writeLine((const U8 *) argv[2]);
  83. }
  84. /*! Use the close method to close the current file handle. If the file was opened for writing, this flushes the contents of the last write to disk.
  85. @return No return value.
  86. @sa openForAppend, openForRead, openForWrite
  87. */
  88. ConsoleMethodWithDocs( FileObject, close, ConsoleVoid, 2, 2, ())
  89. {
  90. object->close();
  91. }
  92. /*!
  93. */
  94. ConsoleMethodWithDocs( FileObject, writeObject, ConsoleVoid, 3, 4, (SimObject, object prepend))
  95. {
  96. SimObject* obj = Sim::findObject( argv[2] );
  97. if( !obj )
  98. {
  99. Con::printf("FileObject::writeObject - Invalid Object!");
  100. return;
  101. }
  102. char *objName = NULL;
  103. if( argc == 4 )
  104. objName = (char*)argv[3];
  105. object->writeObject( obj, (const U8*)objName );
  106. }
  107. ConsoleMethodGroupEndWithDocs(FileObject)