/* Aloe * Copyright (c) 2005 Michael Cohen, Robert C., and Zachary Howe * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU GPL license. See LICENSE for more details * * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include #include #include #include #include #include "aloe.h" #include "file.h" AloeObj* File::reference() { refcount++; return this; } void File::dereference() { refcount--; if (!refcount) delete this; } Context* File::protcon() { return &context; } std::string File::className() { return "File"; } double File::asNum() { return 1; } std::string File::asString() { std::string line; std::string full; std::vector d; while(getline(file, line)) d.push_back(line); for (int i = 0; i args) { if (funcname == "read") { std::string line; std::string full; std::vector d; while(getline(file, line)) d.push_back(line); for (int i = 0; iasString(); file << "Hi\n"; return AloeString::create(args[0]->asString()); } } if (funcname == "input") { std::string str; std::getline(std::cin, str); file << str; return AloeString::create(str); } } File* File::create(std::string name, std::string mode) { return new File(name, mode); } File::File(std::string name, std::string mode) : refcount(1), name(name) { file.open(name.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::ate); if(!file){ std::cout<<"Error: file was not opened, mode was " << mode; } } File::~File() {} AloeObj* File::FileContext::getvar(std::string varname) { return AloeNil::create(); } void File::FileContext::setvar(std::string varname, AloeObj* obj) {} AloeObj* File::FileContext::callfunc(std::string funcname, std::vector args) {}