forked from OctaForge/libcubescript
remove io library (not general enough)
parent
1b12781473
commit
8f1be31ba2
|
@ -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(
|
static inline void cs_do_loop(
|
||||||
CsState &cs, CsIdent &id, CsInt offset, CsInt n, CsInt step,
|
CsState &cs, CsIdent &id, CsInt offset, CsInt n, CsInt step,
|
||||||
CsBytecode *cond, CsBytecode *body
|
CsBytecode *cond, CsBytecode *body
|
||||||
|
@ -1551,9 +1532,6 @@ void cs_init_lib_string(CsState &cs);
|
||||||
void cs_init_lib_list(CsState &cs);
|
void cs_init_lib_list(CsState &cs);
|
||||||
|
|
||||||
OSTD_EXPORT void CsState::init_libs(int libs) {
|
OSTD_EXPORT void CsState::init_libs(int libs) {
|
||||||
if (libs & CS_LIB_IO) {
|
|
||||||
cs_init_lib_io(*this);
|
|
||||||
}
|
|
||||||
if (libs & CS_LIB_MATH) {
|
if (libs & CS_LIB_MATH) {
|
||||||
cs_init_lib_math(*this);
|
cs_init_lib_math(*this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -323,11 +323,10 @@ struct CsIdentLink {
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
CS_LIB_IO = 1 << 0,
|
CS_LIB_MATH = 1 << 0,
|
||||||
CS_LIB_MATH = 1 << 1,
|
CS_LIB_STRING = 1 << 1,
|
||||||
CS_LIB_STRING = 1 << 2,
|
CS_LIB_LIST = 1 << 2,
|
||||||
CS_LIB_LIST = 1 << 3,
|
CS_LIB_ALL = 0b111
|
||||||
CS_LIB_ALL = 0b1111
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OSTD_EXPORT CsState {
|
struct OSTD_EXPORT CsState {
|
||||||
|
|
|
@ -171,6 +171,23 @@ static void do_tty(CsState &cs) {
|
||||||
do_exit = true;
|
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);
|
ostd::writeln(version);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
auto line = read_line(prompt);
|
auto line = read_line(prompt);
|
||||||
|
|
Loading…
Reference in New Issue