feat: add /dump command for Lua expression evaluation and debugging

/dump <expression> evaluates a Lua expression and prints the result to
chat. For tables, iterates key-value pairs and displays them. Aliases:
/print. Useful for addon development and debugging game state queries
like "/dump GetSpellInfo(133)" or "/dump UnitHealth('player')".
This commit is contained in:
Kelsi 2026-03-20 17:05:48 -07:00
parent b3f406c6d3
commit e6fbdfcc02

View file

@ -2620,7 +2620,7 @@ void GameScreen::renderChatWindow(game::GameHandler& gameHandler) {
"/cancelaura", "/cancelform", "/cancellogout", "/cancelshapeshift",
"/cast", "/castsequence", "/chathelp", "/clear", "/clearfocus",
"/clearmainassist", "/clearmaintank", "/cleartarget", "/cloak",
"/combatlog", "/dance", "/dismount", "/dnd", "/do", "/duel",
"/combatlog", "/dance", "/dismount", "/dnd", "/do", "/duel", "/dump",
"/e", "/emote", "/equip", "/equipset",
"/focus", "/follow", "/forfeit", "/friend",
"/g", "/gdemote", "/ginvite", "/gkick", "/gleader", "/gmotd",
@ -6016,6 +6016,30 @@ void GameScreen::sendChatMessage(game::GameHandler& gameHandler) {
return;
}
// /dump <expression> — evaluate Lua expression and print result
if ((cmdLower == "dump" || cmdLower == "print") && spacePos != std::string::npos) {
std::string expr = command.substr(spacePos + 1);
auto* am = core::Application::getInstance().getAddonManager();
if (am && am->isInitialized()) {
// Wrap expression in print(tostring(...)) to display the value
std::string wrapped = "local __v = " + expr +
"; if type(__v) == 'table' then "
" local parts = {} "
" for k,v in pairs(__v) do parts[#parts+1] = tostring(k)..'='..tostring(v) end "
" print('{' .. table.concat(parts, ', ') .. '}') "
"else print(tostring(__v)) end";
am->runScript(wrapped);
} else {
game::MessageChatData errMsg;
errMsg.type = game::ChatType::SYSTEM;
errMsg.language = game::ChatLanguage::UNIVERSAL;
errMsg.message = "Addon system not initialized.";
gameHandler.addLocalChatMessage(errMsg);
}
chatInputBuffer[0] = '\0';
return;
}
// Check addon slash commands (SlashCmdList) before built-in commands
{
auto* am = core::Application::getInstance().getAddonManager();