[clever] r443 committed - Added readln() function in std/io.cc.

0 views
Skip to first unread message

cle...@googlecode.com

unread,
Jul 19, 2011, 10:35:53 PM7/19/11
to cleve...@googlegroups.com
Revision: 443
Author: cad...@gmail.com
Date: Tue Jul 19 19:35:32 2011
Log: Added readln() function in std/io.cc.
http://code.google.com/p/clever/source/detail?r=443

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

Reply all
Reply to author
Forward
0 new messages