use ostd stdin
parent
c9f6ac8be9
commit
3ca2a397dd
2
Makefile
2
Makefile
|
@ -27,7 +27,7 @@ library: $(LIBCS_LIB)
|
||||||
$(LIBCS_LIB): $(LIBCS_OBJ)
|
$(LIBCS_LIB): $(LIBCS_OBJ)
|
||||||
ar rcs $(LIBCS_LIB) $(LIBCS_OBJ)
|
ar rcs $(LIBCS_LIB) $(LIBCS_OBJ)
|
||||||
|
|
||||||
repl: $(LIBCS_LIB)
|
repl: $(LIBCS_LIB) repl.cc
|
||||||
$(CXX) $(CXXFLAGS) $(LIBCS_CXXFLAGS) $(LDFLAGS) repl.cc -o repl $(LIBCS_LIB)
|
$(CXX) $(CXXFLAGS) $(LIBCS_CXXFLAGS) $(LDFLAGS) repl.cc -o repl $(LIBCS_LIB)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|
15
repl.cc
15
repl.cc
|
@ -10,25 +10,26 @@ ostd::ConstCharRange version =
|
||||||
"CubeScript 0.0.1 (REPL mode) Copyright (C) 2016 Daniel \"q66\" Kolesa";
|
"CubeScript 0.0.1 (REPL mode) Copyright (C) 2016 Daniel \"q66\" Kolesa";
|
||||||
CsSvar *prompt = nullptr;
|
CsSvar *prompt = nullptr;
|
||||||
|
|
||||||
static ostd::Maybe<ostd::String> read_line() {
|
static ostd::String read_line() {
|
||||||
ostd::write(prompt->get_value());
|
ostd::write(prompt->get_value());
|
||||||
char buf[512];
|
auto app = ostd::appender<ostd::String>();
|
||||||
if (fgets(buf, sizeof(buf), stdin)) {
|
/* i really need to implement some sort of get_line for ostd streams */
|
||||||
return ostd::String(buf);
|
for (char c = ostd::in.getchar(); c && (c != '\n'); c = ostd::in.getchar()) {
|
||||||
|
app.put(c);
|
||||||
}
|
}
|
||||||
return ostd::nothing;
|
return ostd::move(app.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_tty(CsState &cs) {
|
static void do_tty(CsState &cs) {
|
||||||
ostd::writeln(version);
|
ostd::writeln(version);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
auto line = read_line();
|
auto line = read_line();
|
||||||
if (!line) {
|
if (line.empty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
CsValue ret;
|
CsValue ret;
|
||||||
ret.set_null();
|
ret.set_null();
|
||||||
cs.run_ret(line.value(), ret);
|
cs.run_ret(line, ret);
|
||||||
if (ret.get_type() != CsValueType::null) {
|
if (ret.get_type() != CsValueType::null) {
|
||||||
ostd::writeln(ret.get_str());
|
ostd::writeln(ret.get_str());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue