More work on console I/O and minor fixes
This commit is contained in:
@@ -67,7 +67,11 @@ World::World(util::WorldType wt) {
|
||||
// Initialize the SourceDB. At this stage, the sourcedb is
|
||||
// empty, so it's just populating the lua builtins.
|
||||
source_db_.init(state());
|
||||
source_db_.rebuild(true);
|
||||
std::string srcerrs = source_db_.rebuild();
|
||||
|
||||
// There shouldn't be any lua errors in the sourceDB at this
|
||||
// point, since there's no lua code in the sourceDB.
|
||||
assert(srcerrs == "");
|
||||
|
||||
LS.result();
|
||||
assert (stack_is_clear());
|
||||
@@ -212,8 +216,7 @@ void World::tangible_delete(int64_t id) {
|
||||
assert(LS.istable(database));
|
||||
|
||||
// Clear out the database.
|
||||
LS.clearmetatable(database);
|
||||
LS.cleartable(database);
|
||||
LS.cleartable(database, true);
|
||||
LS.settabletype(database, LUA_TT_DEADTANGIBLE);
|
||||
|
||||
// Remove the lua portion from the tangibles table.
|
||||
@@ -252,6 +255,7 @@ World::Redirects World::fetch_redirects() {
|
||||
}
|
||||
|
||||
int64_t World::create_login_actor() {
|
||||
assert(stack_is_clear());
|
||||
int64_t id = id_global_pool_.get_one();
|
||||
Tangible *tan = tangible_make(state(), id, "nowhere", true);
|
||||
LuaArg database;
|
||||
@@ -323,10 +327,23 @@ void World::update_gui(int64_t actor_id, int64_t place_id, Gui *gui) {
|
||||
}
|
||||
|
||||
void World::update_source(util::LuaSourcePtr source) {
|
||||
assert(stack_is_clear());
|
||||
if (source != nullptr) {
|
||||
source_db_.update(*source);
|
||||
source_db_.rebuild(true);
|
||||
assert(stack_is_clear());
|
||||
std::string errs = source_db_.rebuild();
|
||||
// I don't have a good place to send the error messages right
|
||||
// now. The engine needs a catch-all place to send errors that
|
||||
// occur at unexpected times.
|
||||
std::cerr << errs;
|
||||
}
|
||||
assert(stack_is_clear());
|
||||
}
|
||||
|
||||
void World::run_unittests() {
|
||||
assert(stack_is_clear());
|
||||
source_db_.run_unittests();
|
||||
assert(stack_is_clear());
|
||||
}
|
||||
|
||||
void World::invoke(const Invocation &inv) {
|
||||
@@ -337,6 +354,9 @@ void World::invoke(const Invocation &inv) {
|
||||
case Invocation::KIND_LUA:
|
||||
invoke_lua(inv.actor(), inv.place(), inv.action(), inv.data());
|
||||
break;
|
||||
case Invocation::KIND_FLUSH_PRINTS:
|
||||
invoke_flush_prints(inv.actor(), inv.place(), inv.action(), inv.data());
|
||||
break;
|
||||
default:
|
||||
// Do nothing. Standard behavior for any invalid command is to
|
||||
// simply do nothing at all. Perhaps eventually we may add a flag
|
||||
@@ -347,6 +367,28 @@ void World::invoke(const Invocation &inv) {
|
||||
}
|
||||
}
|
||||
|
||||
void World::invoke_flush_prints(int64_t actor_id, int64_t place_id, const std::string &action, const InvocationData &data) {
|
||||
assert(stack_is_clear());
|
||||
// Check argument sanity.
|
||||
if (actor_id != place_id) {
|
||||
return;
|
||||
}
|
||||
int line = util::strtoint(action, -1);
|
||||
if (line < 0) {
|
||||
return;
|
||||
}
|
||||
Tangible *tactor = tangible_get(actor_id);
|
||||
if (tactor == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (tactor->print_buffer_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
tactor->print_buffer_->discard_upto(line);
|
||||
assert(stack_is_clear());
|
||||
}
|
||||
|
||||
|
||||
void World::invoke_lua(int64_t actor_id, int64_t place_id, const std::string &action, const InvocationData &data) {
|
||||
assert(stack_is_clear());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user