More work on console I/O and minor fixes
This commit is contained in:
@@ -172,7 +172,7 @@ void SourceDB::diff(const SourceDB &auth, StreamBuffer *sb) {
|
||||
SLS.result();
|
||||
}
|
||||
|
||||
void SourceDB::patch(StreamBuffer *sb) {
|
||||
bool SourceDB::patch(StreamBuffer *sb) {
|
||||
lua_State *L = lua_state_;
|
||||
LuaVar db, info;
|
||||
LuaStack LS(L, db, info);
|
||||
@@ -195,7 +195,7 @@ void SourceDB::patch(StreamBuffer *sb) {
|
||||
}
|
||||
}
|
||||
LS.result();
|
||||
if (nupdates > 0) rebuild(false);
|
||||
return (nupdates > 0);
|
||||
}
|
||||
|
||||
void SourceDB::set(const std::string &fn, const std::string &code, int sequence) {
|
||||
@@ -250,7 +250,7 @@ void SourceDB::update(const util::LuaSourceVec &source) {
|
||||
LS.newtable(sourcedb);
|
||||
LS.rawset(LuaRegistry, "sourcedb", sourcedb);
|
||||
}
|
||||
LS.cleartable(sourcedb);
|
||||
LS.cleartable(sourcedb, true);
|
||||
|
||||
for (int i = 0; i < int(source.size()); i++) {
|
||||
const std::string &file = source[i].first;
|
||||
@@ -278,8 +278,10 @@ static void source_clear_globals(lua_State *L) {
|
||||
LS.rawset(globtab, "_G", LuaNil);
|
||||
LS.set(classname, LuaNil);
|
||||
while (LS.next(globtab, classname, classtab) != 0) {
|
||||
if (LS.istable(classtab)) {
|
||||
table_clear(LS, classtab);
|
||||
if (LS.rawequal(globtab, classtab)) {
|
||||
LS.rawset(globtab, classname, LuaNil);
|
||||
} else if (LS.istable(classtab)) {
|
||||
LS.cleartable(classtab, true);
|
||||
} else {
|
||||
LS.rawset(globtab, classname, LuaNil);
|
||||
}
|
||||
@@ -292,6 +294,8 @@ static void source_clear_globals(lua_State *L) {
|
||||
// Load all the 'LuaDefine' C functions into the lua state.
|
||||
//
|
||||
static void source_load_cfunctions(lua_State *L) {
|
||||
LuaVar classobj;
|
||||
LuaStack LS(L, classobj);
|
||||
auto regs = LuaFunctionReg::all();
|
||||
for (const LuaFunctionReg *r : regs) {
|
||||
const std::string &name = r->get_name();
|
||||
@@ -307,24 +311,22 @@ static void source_load_cfunctions(lua_State *L) {
|
||||
lua_CFunction func = r->get_func();
|
||||
std::string mode = r->get_mode();
|
||||
if (mode.find('c') != std::string::npos) { // Insert into class
|
||||
lua_pushlstring(L, classname.c_str(), classname.size());
|
||||
lfn_source_makeclass(L);
|
||||
lua_pushcfunction(L, func);
|
||||
lua_setfield(L, -2, funcname.c_str());
|
||||
LS.makeclass(classobj, classname);
|
||||
LS.rawset(classobj, funcname, func);
|
||||
}
|
||||
if (mode.find('f') != std::string::npos) { // Make global function
|
||||
lua_pushcfunction(L, func);
|
||||
lua_setglobal(L, funcname.c_str());
|
||||
LS.getglobaltable(classobj);
|
||||
LS.rawset(classobj, funcname, func);
|
||||
}
|
||||
}
|
||||
LS.result();
|
||||
}
|
||||
|
||||
// Run all the closures from the source database.
|
||||
//
|
||||
static void source_load_lfunctions(lua_State *L, bool print_errors) {
|
||||
LuaRet errors;
|
||||
static std::string source_load_lfunctions(lua_State *L) {
|
||||
LuaVar sourcedb, key, info, seq, closure, err;
|
||||
LuaStack LS(L, sourcedb, errors, key, info, seq, closure, err);
|
||||
LuaStack LS(L, sourcedb, key, info, seq, closure, err);
|
||||
|
||||
// Get the source database.
|
||||
LS.rawget(sourcedb, LuaRegistry, "sourcedb");
|
||||
@@ -349,9 +351,7 @@ static void source_load_lfunctions(lua_State *L, bool print_errors) {
|
||||
|
||||
// If there's already an error in the sourcedb, collect it.
|
||||
if (!LS.isfunction(closure)) {
|
||||
if (print_errors) {
|
||||
errss << LS.ckstring(closure) << "\n";
|
||||
}
|
||||
errss << LS.ckstring(closure) << "\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -362,22 +362,17 @@ static void source_load_lfunctions(lua_State *L, bool print_errors) {
|
||||
errss << LS.ckstring(err);
|
||||
}
|
||||
}
|
||||
LS.set(errors, errss.str());
|
||||
LS.result();
|
||||
return errss.str();
|
||||
}
|
||||
|
||||
void SourceDB::rebuild(bool print_errors) {
|
||||
std::string SourceDB::rebuild() {
|
||||
lua_State *L = lua_state_;
|
||||
LuaVar errs;
|
||||
LuaStack LS(L, errs);
|
||||
source_clear_globals(L);
|
||||
source_install_builtins(L);
|
||||
source_load_cfunctions(L);
|
||||
source_load_lfunctions(L, print_errors);
|
||||
lua_replace(L, errs.index());
|
||||
std::string errstr = LS.ckstring(errs);
|
||||
std::cerr << errstr;
|
||||
LS.result();
|
||||
std::string errs = source_load_lfunctions(L);
|
||||
return errs;
|
||||
}
|
||||
|
||||
void SourceDB::run_unittests() {
|
||||
|
||||
Reference in New Issue
Block a user