Can now use /CPL to reload lua source
This commit is contained in:
@@ -79,6 +79,10 @@ public:
|
||||
|
||||
// Set the console prompt
|
||||
get_stdio_channel()->set_prompt(console_.get_prompt());
|
||||
|
||||
// The driver loads the lua source automatically.
|
||||
// However, we don't need it. Throw it out.
|
||||
get_lua_source();
|
||||
}
|
||||
|
||||
void send_invocation(const Invocation &inv) {
|
||||
@@ -94,6 +98,14 @@ public:
|
||||
inv.serialize(sb);
|
||||
}
|
||||
|
||||
void send_lua_source(const util::LuaSourceVec &sv) {
|
||||
StreamBuffer serial;
|
||||
SourceDB::serialize_source(sv, &serial);
|
||||
std::string sstr = serial.read_entire_contents();
|
||||
Invocation inv(Invocation::KIND_LUA_SOURCE, actor_id_, actor_id_, sstr);
|
||||
send_invocation(inv);
|
||||
}
|
||||
|
||||
void do_luainvoke_command(const StringVec &words) {
|
||||
send_invocation(Invocation(Invocation::KIND_LUA, actor_id_, actor_id_, words[1]));
|
||||
}
|
||||
@@ -134,6 +146,10 @@ public:
|
||||
send_invocation(Invocation(Invocation::KIND_TICK, actor_id_, actor_id_, ""));
|
||||
}
|
||||
|
||||
void do_cpl_command(const util::StringVec &words) {
|
||||
rescan_lua_source();
|
||||
}
|
||||
|
||||
void do_quit_command(const util::StringVec &words) {
|
||||
abandon_server();
|
||||
stop_driver();
|
||||
@@ -148,6 +164,7 @@ public:
|
||||
else if (words[0] == "menu") do_menu_command(words);
|
||||
else if (words[0] == "choose") do_choose_command(words);
|
||||
else if (words[0] == "tick") do_tick_command(words);
|
||||
else if (words[0] == "cpl") do_cpl_command(words);
|
||||
else if (words[0] == "quit") do_quit_command(words);
|
||||
else {
|
||||
stdostream() << "Unsupported command: " << words[0] << std::endl;
|
||||
@@ -214,6 +231,14 @@ public:
|
||||
}
|
||||
|
||||
virtual void event_update() {
|
||||
// Check for lua source code. If this returns non-null,
|
||||
// it is because somebody typed CPL.
|
||||
util::LuaSourcePtr lua_source = get_lua_source();
|
||||
if (lua_source != nullptr) {
|
||||
send_lua_source(*lua_source);
|
||||
lua_source.reset();
|
||||
}
|
||||
|
||||
// Check for keyboard input on stdin.
|
||||
while (true) {
|
||||
std::string line = get_stdio_channel()->in()->readline();
|
||||
|
||||
Reference in New Issue
Block a user