only print Lua command result if it's not null

This commit is contained in:
Kae 2024-07-27 13:58:14 +10:00
parent f95fbc3a37
commit 9e7a2e9bb9
2 changed files with 8 additions and 3 deletions

View File

@ -21,6 +21,8 @@ command("run", function(src)
local success, result = pcall(result)
if not success then
return "^#f00;error: " .. result
elseif result == nil then
return nil
else
local success, printed = pcall(sb.printJson, result)
if not success then

View File

@ -91,9 +91,12 @@ StringList ClientCommandProcessor::handleCommand(String const& commandLine) {
}
} else {
auto player = m_universeClient->mainPlayer();
if (auto messageResult = player->receiveMessage(connectionForEntity(player->entityId()), "/" + command, { allArguments }))
result.append(messageResult->isType(Json::Type::String) ? *messageResult->stringPtr() : messageResult->repr(1, true));
else
if (auto messageResult = player->receiveMessage(connectionForEntity(player->entityId()), "/" + command, {allArguments})) {
if (messageResult->isType(Json::Type::String))
result.append(*messageResult->stringPtr());
else if (!messageResult->isNull())
result.append(messageResult->repr(1, true));
} else
m_universeClient->sendChat(commandLine, ChatSendMode::Broadcast);
}
return result;