A few assorted cleanups.
This commit is contained in:
@@ -46,7 +46,9 @@ static void l_message(const char *msg)
|
||||
}
|
||||
|
||||
void TextGame::do_lua(const std::string &exp) {
|
||||
assert(world_->stack_is_clear());
|
||||
lua_State *L = world_->state();
|
||||
// push the compiled function.
|
||||
int status = luaL_loadbuffer(L, exp.c_str(), exp.size(), "=stdin");
|
||||
assert(status == LUA_OK);
|
||||
globalL = L;
|
||||
@@ -67,6 +69,7 @@ void TextGame::do_lua(const std::string &exp) {
|
||||
lua_pop(L, 1);
|
||||
lua_gc(L, LUA_GCCOLLECT, 0);
|
||||
}
|
||||
assert(world_->stack_is_clear());
|
||||
}
|
||||
|
||||
void TextGame::do_view_command(const StringVec &cmd) {
|
||||
@@ -138,6 +141,17 @@ void TextGame::do_rollback_command(const StringVec &cmd) {
|
||||
world_->rollback();
|
||||
}
|
||||
|
||||
void TextGame::do_tick_command(const StringVec &cmd) {
|
||||
int64_t clock;
|
||||
if (cmd.size() == 2) {
|
||||
clock = util::strtoint(cmd[1], -1);
|
||||
} else {
|
||||
std::cerr << "t command (tick) expects a time value" << std::endl;
|
||||
return;
|
||||
}
|
||||
world_->run_scheduled_threads(clock);
|
||||
}
|
||||
|
||||
void TextGame::do_quit_command(const StringVec &cmd) {
|
||||
if (cmd.size() != 1) {
|
||||
std::cerr << "q command (quit) takes no arguments" << std::endl;
|
||||
@@ -153,6 +167,7 @@ void TextGame::do_command(const StringVec &words) {
|
||||
else if (words[0] == "q") do_quit_command(words);
|
||||
else if (words[0] == "s") do_snapshot_command(words);
|
||||
else if (words[0] == "r") do_rollback_command(words);
|
||||
else if (words[0] == "t") do_tick_command(words);
|
||||
else if (util::validinteger(words[0])) do_choose_command(words);
|
||||
else {
|
||||
std::cerr << "Unknown command: " << words[0] << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user