Repr – function for printing tables

It’s interesting that this goes out of its way to canonize the infinities (math.huge/-math.huge) but doesn’t do the same for NaN.

The plugin also seems to not work for me. It’s not setting the global.

Just updated the plugin - try one more time. The original had an issue where the plugin was running on client (accurate play solo) and spitting out an error. The band-aid fix had an issue as well, but I’ve re-checked it and everything should work as intended.

To be clear, the plugin won’t set the global if RunService:IsServer() returns false because only the server can require(assetId).

I may have neglected this detail. Sorry!

Is it just me being a noob or does this module not support Roblox types?:confused:

Code used to test. Was trying to learn the
local repr = require(3148021300)

local region = Region3.new(Vector3.new(-8, -8, -8), Vector3.new(8, 8, 8))
print(repr(game.Workspace.Terrain:ReadVoxels(region, 4), {pretty = true, robloxFullName = false, robloxProperFullName = true, robloxClassName = true}))

Here’s a module made by Partixel that works with roblox types, cyclic tables and metatables

2 Likes

I’ll add support for more Roblox types today.

Update: repr now supports all Roblox data types. It presents each data type using its closest constructor. Update the plugin.

Thank you for this! As a guy who HATES string manipulation, this is a major blessing from above.


Quick question: Have you attempted to make an OOP version of this? For example, it would be amazing to do:

print(myTable:repr(options));

Not forcing you, just a question to see if this would be compatible with OOP in the first place. (I have some time later so I may try to implement it myself.)

1 Like

Implementing this would be trivial:

t.repr = repr
t:repr(options)

You could use your own constructor to construct tables for consistent access to the function:

local function newTable(initialTable)
    initialTable.repr = repr
    return initialTable
end

local t = newTable({key = "value", otherKey = "otherValue"})
print(t:repr()) --> {key = "key", otherKey = "otherValue"}
2 Likes

Yep, that’s exactly what I came up with. Oh well. It was worth a shot. Thank you though.

Although the t.repr = repr isn’t actually super bad thinking about it now… One line of code for OOP use isn’t bad (considering all the other junk we have to use to get classes and such).

Edit: And Discourse decide to break my spoiler. I guess code and blur don’t go well together…

I’ve considered it. This is just the down-and-dirty “I want something printed, now” version. I’d like to make something like this possible:

local repr = require(...):default{pretty=true,semicolons=true}
local someTable = {...}
print(repr(someTable))

And to answer your question, yes! - it would be pretty easy to add :repr() methods to objects, given how colon-syntax works.

1 Like

This would’ve come in handy back when GetBundleDetailsAsync had no documentation (it was such a chore for me to manually print the returns) and I’m sure it’ll have great future usage for debugging. Cheers.

One thing to mention: the article linked in the thread is actually to the page for GetBundleDetailsSync, not GetBundleDetailsAsync. May want to correct that (and maybe specify what the former is for, since that has no documentation).

1 Like

I’ve updated the plugin to also expose _G.print_repr, which sends the result to print before returning it. So you can do even shorter checks in the command bar:

_G.print_repr{holy_cow = "it's a new update"} --> {holy_cow = "it's a new update"}

Update it from within Studio’s Plugins tab, under Manage Plugins:

2 Likes

This is pretty nice. I had my own function for this, but often ended up getting incorrect indents for whatever reason. Definitely going to use this.

Nice job, I was messing around with Players and Tables the other day and I kicked myself for the table printing something useless to me! Thanks.

Amazing module! Just noticed a small typo on line 278 where you forgot to include a closing ‘)’ in the string when printing out Vector2 values. image

3 Likes

Are you still maintaining this Module? @Ozzypig

The function get’s stuck when I pass an Indirect Cyclic Table.

I would like to provide more Detail and a working Repro, in private

2 Likes

I’d be happy to make an update if it fixes a critical bug. Can you be more specific?

That’s cool. I very like the idea but there’s already an easy way to print table

 local table = {"hello",3,true}
 for _,v in pairs(table) do
 print(v) -- prints table's content
 end

but I think your way is quicker and will help me a lot
Have a nice day

This is really helpful! Now I don’t have to iterate through all indexes everytime I want to print! A quick suggestion, investigate on how this module allows the implementation of custom methods in Roblox interfaces. For example adding methods to the global math library. This would allow you to add the table.print() method. Cheers!

Really great module, it’s incredibly useful for me while I’m working on inventory systems

yes that’s fine for basic printing, but the main use of this module I would say is deep printing, and making prints more readable

example>
image