"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

2 Likes

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

1 Like

We have prepared a fix for this issue.
We will post an update after it’s released.

1 Like

When did Roblox Studio change in what order the table prints out as?

local tbl = {
	["c"] = "test",
	["a"] = "test"
}

print(tbl)
for k,v in pairs(tbl) do print(k,v) end

I just noticed this after running the above code for the re-production steps.

Why is Roblox Studio sorting its own print table alphabetically now?

Looks like the fix is out, is it true? And this looks to be fixed now, as the Re-production steps example now run the __tostring

 

I am wondering about this though.

The fix for the issue has been released.

I don’t work on Studio output, but sorting was supported since 2021.

1 Like

oh I think it’s because of the __ in my repro compared to the screenshot I took for the actual result, yeah I got confused, I think it’s fine

Very cool, thanks for the fix!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.