Skip to content

Commit 137bee9

Browse files
committed
fix: fix debug command
1 parent 32d467a commit 137bee9

File tree

2 files changed

+29
-43
lines changed

2 files changed

+29
-43
lines changed

src/legacy/api/CommandAPI.cpp

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -235,17 +235,6 @@ Local<Value> McClass::newCommand(const Arguments& args) {
235235
try {
236236
auto name = args[0].asString().toString();
237237

238-
auto registry = ll::service::getCommandRegistry();
239-
if (registry) {
240-
auto instance = registry->findCommand(name);
241-
if (instance) {
242-
lse::getSelfPluginInstance().getLogger().info(
243-
"Runtime command {} already exists, changes will not beapplied except for setOverload!"_tr(name)
244-
);
245-
return CommandClass::newCommand(name);
246-
}
247-
}
248-
249238
auto desc = args[1].asString().toString();
250239
CommandPermissionLevel permission = CommandPermissionLevel::Admin;
251240
CommandFlag flag = {(CommandFlagValue)0x80};
@@ -261,20 +250,33 @@ Local<Value> McClass::newCommand(const Arguments& args) {
261250
}
262251
}
263252
}
264-
if (ll::getGamingStatus() == ll::GamingStatus::Starting) {
265-
EventBus::getInstance().emplaceListener<ServerStartedEvent>(
266-
[name, desc, permission, flag, alias](ServerStartedEvent&) {
267-
auto& command = CommandRegistrar::getInstance().getOrCreateCommand(name, desc, permission, flag);
268-
if (!alias.empty()) {
269-
command.alias(alias);
270-
}
253+
auto newCommandFunc = [](std::string const& name,
254+
std::string const& desc,
255+
CommandPermissionLevel const& permission,
256+
CommandFlag const& flag,
257+
std::string const& alias) {
258+
auto registry = ll::service::getCommandRegistry();
259+
if (registry) {
260+
auto instance = registry->findCommand(name);
261+
if (instance) {
262+
lse::getSelfPluginInstance().getLogger().info(
263+
"Runtime command {} already exists, changes will not beapplied except for setOverload!"_tr(name)
264+
);
271265
}
272-
);
273-
} else {
266+
}
274267
auto& command = CommandRegistrar::getInstance().getOrCreateCommand(name, desc, permission, flag);
275268
if (!alias.empty()) {
276269
command.alias(alias);
277270
}
271+
};
272+
if (ll::getGamingStatus() == ll::GamingStatus::Starting) {
273+
EventBus::getInstance().emplaceListener<ServerStartedEvent>(
274+
[name, desc, permission, flag, alias, newCommandFunc](ServerStartedEvent&) {
275+
newCommandFunc(name, desc, permission, flag, alias);
276+
}
277+
);
278+
} else {
279+
newCommandFunc(name, desc, permission, flag, alias);
278280
}
279281
return CommandClass::newCommand(name);
280282
}
@@ -471,8 +473,9 @@ Local<Value> CommandClass::optional(const Arguments& args) {
471473
Local<Value> CommandClass::addOverload(const Arguments& args) {
472474
try {
473475
if (args.size() == 0) return Boolean::newBoolean(true);
474-
auto overloadFunc = [](RuntimeOverload& cmd, std::string const& commandName, std::string const& paramName) {
475-
auto& paramList = getEngineOwnData()->plugin->registeredCommands[commandName];
476+
auto overloadFunc = [e(EngineScope::currentEngine()
477+
)](RuntimeOverload& cmd, std::string const& commandName, std::string const& paramName) {
478+
auto& paramList = getEngineData(e)->plugin->registeredCommands[commandName];
476479
for (auto& info : paramList) {
477480
if (info.name == paramName || info.enumName == paramName) {
478481
if (info.optional) {
@@ -501,24 +504,7 @@ Local<Value> CommandClass::addOverload(const Arguments& args) {
501504
.getOrCreateCommand(commandName)
502505
.runtimeOverload(getEngineData(e)->plugin);
503506
for (auto& paramName : enumValues) {
504-
auto& paramList = getEngineData(e)->plugin->registeredCommands[commandName];
505-
for (auto& info : paramList) {
506-
if (info.name == paramName || info.enumName == paramName) {
507-
if (info.optional) {
508-
if (info.type == ParamKind::Kind::Enum || info.type == ParamKind::Kind::SoftEnum) {
509-
cmd.optional(info.enumName, info.type, info.enumName).option(info.option);
510-
} else {
511-
cmd.optional(info.name, info.type).option(info.option);
512-
}
513-
} else {
514-
if (info.type == ParamKind::Kind::Enum || info.type == ParamKind::Kind::SoftEnum) {
515-
cmd.required(info.enumName, info.type, info.enumName).option(info.option);
516-
} else {
517-
cmd.required(info.name, info.type).option(info.option);
518-
}
519-
}
520-
}
521-
}
507+
overloadFunc(cmd, commandName, paramName);
522508
}
523509
cmd.execute(onExecute);
524510
});

src/legacy/main/BuiltinCommands.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@ bool ProcessDebugEngine(const std::string& cmd) {
4646
}
4747

4848
struct EngineDebugCommand {
49-
std::string eval;
49+
CommandRawText eval;
5050
};
5151

5252
void RegisterDebugCommand() {
5353
auto& command = ll::command::CommandRegistrar::getInstance()
5454
.getOrCreateCommand(LLSE_DEBUG_CMD, "Debug LegacyScriptEngine", CommandPermissionLevel::Owner);
5555
command.overload<EngineDebugCommand>().optional("eval").execute(
5656
[](CommandOrigin const&, CommandOutput& output, EngineDebugCommand const& param) {
57-
if (!param.eval.empty()) {
57+
if (!param.eval.getText().empty()) {
5858
EngineScope enter(debugEngine);
5959
try {
60-
auto result = debugEngine->eval(param.eval);
60+
auto result = debugEngine->eval(param.eval.getText());
6161
std::ostringstream sout;
6262
PrintValue(sout, result);
6363
output.success(sout.str());

0 commit comments

Comments
 (0)