WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   How to dump a table to the screen (https://www.wowinterface.com/forums/showthread.php?t=59599)

AeroMaxxD 05-30-23 11:40 AM

How to dump a table to the screen
 
Is there a lua equivalent to var_dump from https://www.php.net/manual/en/function.var-dump.php

Basically I wanting to know what's inside a table.

Fizzlemizz 05-30-23 12:16 PM

Code:

/dump <table name>
but the table has to be global.

Otherwise, in code you could:
Lua Code:
  1. DevTools_Dump(table)

Edited after remembering DevTools had changed from it's original incarnation thanks to wardz and LudiusMaximus.

wardz 05-30-23 12:18 PM

/dump table
/run DevTools_DumpCommand("table")
/run DevTools_Dump(table)


Edit; might need UIParentLoadAddOn("Blizzard_DebugTools") if not using /dump

LudiusMaximus 05-30-23 03:16 PM

When I want to search recursively for strings in tables, I use this function:

Lua Code:
  1. local function PrintTable(t, indent)
  2.   assert(type(t) == "table", "PrintTable() called for non-table!")
  3.  
  4.   local indentString = ""
  5.   for i = 1, indent do
  6.     indentString = indentString .. "  "
  7.   end
  8.  
  9.   for k, v in pairs(t) do
  10.     if type(v) ~= "table" then
  11.       if type(v) == "string" then
  12.         print(indentString, k, "=", v)
  13.       end
  14.     else
  15.       print(indentString, k, "=")
  16.       print(indentString, "  {")
  17.       PrintTable(v, indent + 2)
  18.       print(indentString, "  }")
  19.     end
  20.   end
  21. end
  22.  
  23. PrintTable(tableToPrint, 1)

SDPhantom 05-31-23 12:45 AM

The built-in DevTools also supplies a /tableinspect command that allows you to navigate tables in an inspection window.


All times are GMT -6. The time now is 01:35 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI