File library fixes

This commit is contained in:
2025-10-06 18:00:09 +11:00
parent e89d7ffacc
commit e0ec910dc2

View File

@@ -22,17 +22,12 @@ Value modules::file(std::vector<Value> args) {
} }
std::string buf; std::string buf;
std::string retval; std::string retval;
bool notfirst = false;
while (getline(file, buf)) { while (getline(file, buf)) {
if (notfirst) { buf += "\n";
buf += "\n";
} else {
notfirst = true;
}
retval += buf; retval += buf;
} }
file.close(); file.close();
return Value(retval); return Value("\"" + retval + "\"");
} else if (args[0].string_val == "readlines") { } else if (args[0].string_val == "readlines") {
std::ifstream file(args[1].string_val); std::ifstream file(args[1].string_val);
if (!file) { if (!file) {
@@ -42,7 +37,7 @@ Value modules::file(std::vector<Value> args) {
std::string buf; std::string buf;
std::vector<Value> retval; std::vector<Value> retval;
while (getline(file, buf)) { while (getline(file, buf)) {
retval.push_back(Value(buf)); retval.push_back(Value("\"" + buf + "\""));
} }
file.close(); file.close();
return Value(retval); return Value(retval);