Файловый объект обеспечивает чтение и запись файлов.
Регистрируется с помощью RegisterScriptFile(asIScriptEngine*).
Если вы хотите отказаться от поддержки записи - укажете в заголовочном файле AS_WRITE_OPS 0.
class CScriptFile { public: // Конструктор CScriptFile(); // Управление памятью void AddRef(); void Release(); // mode = "r" -> чтение // mode = "w" -> запись с перезаписью // mode = "a" -> запись с добавлением int Open(const std::string &filename, const std::string &mode); int Close(); // Возвращает размер int GetSize() const; // Возвращает true если достигнут конец файла bool IsEOF() const; // Читает строку определенного размера int ReadString(unsigned int length, std::string &str); // Читает строку до /n int ReadLine(std::string &str); // Пишет строку в файл int WriteString(const std::string &str); // Управление курсором int GetPos() const; int SetPos(int pos); int MovePos(int delta); };
class file
{
int open(const string &in filename, const string &in mode);
int close();
int getSize() const;
bool isEndOfFile() const;
int readString(uint length, string &out str);
int readLine(string &out str);
int writeString(const string &in string);
int getPos() const;
int setPos(int pos);
int movePos(int delta);
}
file f;
// Open the file in 'read' mode
if( f.open("file.txt", "r") >= 0 )
{
// Read the whole file into the string buffer
string str;
f.readString(f.getSize(), str);
f.close();
}