remove io library (not general enough)

master
Daniel Kolesa 2016-09-02 18:59:04 +01:00
parent 1b12781473
commit 8f1be31ba2
3 changed files with 21 additions and 27 deletions

View File

@ -1246,25 +1246,6 @@ CsCommand *CsState::new_command(
);
}
void cs_init_lib_io(CsState &cs) {
cs.new_command("exec", "sb", [&cs](CsValueRange args, CsValue &res) {
auto file = args[0].get_strr();
bool ret = cs.run_file(file);
if (!ret) {
if (args[1].get_int()) {
ostd::err.writefln("could not run file \"%s\"", file);
}
res.set_int(0);
} else {
res.set_int(1);
}
});
cs.new_command("echo", "C", [](CsValueRange args, CsValue &) {
ostd::writeln(args[0].get_strr());
});
}
static inline void cs_do_loop(
CsState &cs, CsIdent &id, CsInt offset, CsInt n, CsInt step,
CsBytecode *cond, CsBytecode *body
@ -1551,9 +1532,6 @@ void cs_init_lib_string(CsState &cs);
void cs_init_lib_list(CsState &cs);
OSTD_EXPORT void CsState::init_libs(int libs) {
if (libs & CS_LIB_IO) {
cs_init_lib_io(*this);
}
if (libs & CS_LIB_MATH) {
cs_init_lib_math(*this);
}

View File

@ -323,11 +323,10 @@ struct CsIdentLink {
};
enum {
CS_LIB_IO = 1 << 0,
CS_LIB_MATH = 1 << 1,
CS_LIB_STRING = 1 << 2,
CS_LIB_LIST = 1 << 3,
CS_LIB_ALL = 0b1111
CS_LIB_MATH = 1 << 0,
CS_LIB_STRING = 1 << 1,
CS_LIB_LIST = 1 << 2,
CS_LIB_ALL = 0b111
};
struct OSTD_EXPORT CsState {

View File

@ -171,6 +171,23 @@ static void do_tty(CsState &cs) {
do_exit = true;
});
cs.new_command("exec", "sb", [&cs](CsValueRange args, CsValue &res) {
auto file = args[0].get_strr();
bool ret = cs.run_file(file);
if (!ret) {
if (args[1].get_int()) {
ostd::err.writefln("could not run file \"%s\"", file);
}
res.set_int(0);
} else {
res.set_int(1);
}
});
cs.new_command("echo", "C", [](CsValueRange args, CsValue &) {
ostd::writeln(args[0].get_strr());
});
ostd::writeln(version);
for (;;) {
auto line = read_line(prompt);