luaadd-onworld-of-warcraft

Unable to Print Lua Table Key\Index & Values


A table received from a Gaming API (World of Warcraft) prints the following result as a whole

local sometbl = APICommand("args");
print(sometbl) --prints table: 000001F492F31.... 

basically some memory address I presume.

while trying either print(sometbl[1]) or print(sometbl[2]) the output is nil.

While trying

for key, value in next, sometbl do
    print(key .. " ".. value)
end

OR

for key, value in pairs(sometbl) do
    print(key .. " ".. value)
end

OR

for key, value in ipairs(sometbl) do
    print(key .. " ".. value)
end

No output is generated from any of these.

the print(sometbl) still prints said memory reference

How do can I print the entire contents of that peculiar table?


Solution

  • If

    for key, value in pairs(sometbl) do
        print(key .. " ".. value)
    end
    

    prints nothing the table is empty. So there is no content to print.

    next(sometbl) will return nil if the table is empty.