How to get the table name in coding

Hey guys, I’m a Solar2D beginner, just ask a question:

I want to make a debug function for printing all contents from a table. for example:
local aTable = { a = 1, b = ‘text’ }

–table name: aTable
----content a: 1
----content b: ‘text’

To print the contents way is done, but how could I get the table name?

You have to write the table’s name manually. For the keys and their values you can do this:

for key, value in pairs(aTable) do
    print(key, value)

If you want to make a prettier output, you may need to use tostring(), like…
print("--- "..tostring(key)..": ".. tostring(value))

If you have a table as a value, it is going to print it’s address, if you want to print their contents too, look at this tool:

Thanks for your reply.

But my question is that how to get the table name, if I want to print my table name “aTable”.

Lua have functions “debug.traceback()” and “debug.getInfo()”, they can print a string which is name of coding file(…/Game.lua) or which function is a place for now(…onPlay()). Have any function can get name like these? I just would like get Table name in coding.

I dont know about these functions. What I would do is just put .name property in table to have it printed with content…if this is an option.

local myTable = {} = "myTable"
myTable.a = 1
myTable.b = "text"

This is probalbly the easiest way to do it…