Refactor code for invoke_lua_source and world.init. Also, add compile_commands.json to luprex
This commit is contained in:
@@ -29,24 +29,19 @@ public:
|
||||
PrintChanneler print_channeler_;
|
||||
HttpChannelMap http_client_channels_;
|
||||
HttpChannelVec http_server_channels_;
|
||||
int64_t admin_id_;
|
||||
int next_diff_chan_;
|
||||
double next_tick_;
|
||||
eng::vector<Invocation> delayed_invocations_;
|
||||
int64_t admin_id_ = 0;
|
||||
double next_tick_ = 0;
|
||||
|
||||
public:
|
||||
virtual void event_init(std::string_view srcpk, int argc, char *argv[]) override {
|
||||
LpxServer()
|
||||
{
|
||||
// Create the master world model.
|
||||
master_.reset(new World(WORLD_TYPE_MASTER));
|
||||
|
||||
// Update the source code of the master model.
|
||||
master_->update_source(srcpk);
|
||||
|
||||
// Create an actor for administrative commands.
|
||||
// Create the admin actor. Note: there isn't any 'init' function yet.
|
||||
admin_id_ = master_->create_login_actor();
|
||||
|
||||
// TODO: initialize the admin actor.
|
||||
|
||||
// Print out admin ID for debugging purposes.
|
||||
stdostream() << "Admin actor id = " << admin_id_ << std::endl;
|
||||
|
||||
@@ -61,9 +56,9 @@ public:
|
||||
|
||||
// Export stuff to the graphics engine.
|
||||
set_visible_world_and_actor(master_.get(), admin_id_);
|
||||
|
||||
// for ticking.
|
||||
next_tick_ = 0.0;
|
||||
|
||||
// Trigger the loading of the lua source.
|
||||
rescan_lua_source();
|
||||
}
|
||||
|
||||
virtual void do_syntax_error(std::string_view error) override {
|
||||
@@ -91,35 +86,7 @@ public:
|
||||
}
|
||||
|
||||
virtual void do_work_command() override {
|
||||
master_->snapshot();
|
||||
StreamBuffer datapack;
|
||||
StreamBuffer retvals;
|
||||
datapack.write_string("engio");
|
||||
datapack.write_string("myfunction");
|
||||
datapack.write_simple_dynamic_tag(SimpleDynamicTag::NUMBER);
|
||||
datapack.write_double(3.7);
|
||||
datapack.write_simple_dynamic_tag(SimpleDynamicTag::STRING);
|
||||
datapack.write_string("banana");
|
||||
datapack.write_simple_dynamic_tag(SimpleDynamicTag::BOOLEAN);
|
||||
datapack.write_bool(true);
|
||||
master_->probe_lua_call(admin_id_, admin_id_, datapack.view(), &retvals);
|
||||
while (!retvals.empty()) {
|
||||
SimpleDynamicValue value;
|
||||
retvals.read_simple_dynamic(&value);
|
||||
if (value.type == SimpleDynamicTag::NUMBER) {
|
||||
util::dprint("retval: ", value.x);
|
||||
} else if (value.type == SimpleDynamicTag::STRING) {
|
||||
util::dprint("retval: ", value.s);
|
||||
} else if (value.type == SimpleDynamicTag::BOOLEAN) {
|
||||
util::dprint(value.x ? "retval: true" : "retval: false");
|
||||
} else if (value.type == SimpleDynamicTag::VECTOR) {
|
||||
util::dprint("retval: ", value.x, " ", value.y, " ", value.z);
|
||||
} else {
|
||||
util::dprint("retval: invalid");
|
||||
break;
|
||||
}
|
||||
}
|
||||
master_->rollback();
|
||||
do_unknown_command("work");
|
||||
}
|
||||
|
||||
virtual void do_display_command() override {
|
||||
@@ -194,7 +161,16 @@ public:
|
||||
}
|
||||
|
||||
virtual void event_access(AccessKind kind, int64_t place_id, std::string_view datapk, StreamBuffer *retpk) override {
|
||||
if (place_id == 0) place_id = admin_id_;
|
||||
switch (kind) {
|
||||
case AccessKind::INVOKE_LUA_CALL:
|
||||
case AccessKind::INVOKE_LUA_EXPR:
|
||||
case AccessKind::INVOKE_FLUSH_PRINTS:
|
||||
case AccessKind::INVOKE_TICK:
|
||||
case AccessKind::INVOKE_LUA_SOURCE: {
|
||||
delayed_invocations_.emplace_back(kind, admin_id_, place_id, datapk);
|
||||
break;
|
||||
}
|
||||
case AccessKind::PROBE_LUA_CALL: {
|
||||
master_->snapshot();
|
||||
master_->probe_lua_call(admin_id_, place_id, datapk, retpk);
|
||||
@@ -202,7 +178,7 @@ public:
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
delayed_invocations_.emplace_back(kind, admin_id_, place_id, datapk);
|
||||
stdostream() << "Invalid event_access: " << int(kind) << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user