"print" on tables skips __tostring on table types, while it supports it for light userdata types

Description

This is how Userdata with __tostring appears, when using print on a table, where the object is put as the key.

Like so:

print({
    [object_here] = "value"
})

image

However, tables have this skipped.

image

Re-production steps

  1. Run this in Studio
local object = newproxy(true)
getmetatable(object).__tostring = function()
	return "__tostring from userdata"
end

local object2 = setmetatable({}, {
	__tostring = function()
		return "__tostring from table"
	end,
})


print("Userdata __tostring:", object)
print("Table __tostring:", object2)

print({
	[object] = "userdata test",
	[object2] = "table test"
})
  1. Observe the Output Window

Expected Result

I expected this part
image

to use the corresponding __tostring as well, but it didn’t

If __tostring is declared on a metatable of a table, I expected the pretty print to use __tostring.

Actual Result

__tostring from newproxy’s modified metatable was used. But the one from the actual table wasn’t used.

image

1 Like

Thanks for the report! I filed a ticket in our internal database.