Modified:
/trunk/modules/std/io.cc
=======================================
--- /trunk/modules/std/io.cc Sat Jan 29 11:43:24 2011
+++ /trunk/modules/std/io.cc Tue Jul 19 19:35:32 2011
@@ -29,6 +29,7 @@
#include "value.h"
#include "module.h"
#include "std/io.h"
+#include "typetable.h"
namespace clever { namespace std_pkg {
@@ -51,13 +52,29 @@
std::cout << args->at(i)->toString() << std::endl;
}
}
+
+/**
+ * readln()
+ * Reads a line from the standard input.
+ */
+static CLEVER_FUNCTION(readln) {
+ std::string buffer;
+
+ getline(std::cin, buffer);
+
+ retval->setString(CSTRING(buffer));
+ retval->set_type(Value::STRING);
+}
/**
* Initializes Standard module
*/
void IOModule::Init() throw() {
+ const Type* string_type = TypeTable::getType(CSTRING("String"));
+
addFunction(new Function("print", &CLEVER_FUNC_NAME(print), -1));
addFunction(new Function("println", &CLEVER_FUNC_NAME(println), -1));
+ addFunction(new Function("readln", &CLEVER_FUNC_NAME(readln),
string_type));
}
}} // clever::std_pkg