Make concatenate operator ".." work on tables

The only good reasoning I’ve seen on this thread against making … work with tables is that it’s inconsistent with what Lua normally does. I like Shedletsky’s debug print idea, that just tries to do whatever it can to print out what it’s given.

The first step in debugging is to understand what the bug is causing. Without printing out the table, you can’t fully understand what’s going wrong. Is table.Health nil because it got overwritten? Is table.Health nil because you made a typo? Is table.Health nil because it somehow got nested in a different table? The quickest way to find that out is printing out the table.

Just… go tap @0xBAADF00D on the shoulder. I’m sure he could toss this in real quick.

no way d00d

1 Like

I think you meant tostring()

You could use a metatable with the __concat field to make it be formatted as a string when …'ed.

That would be nice to have indeed.

That would be nice to have too indeed.

And all this because doing something as simple as overwriting print/warn/tostring very quickly isn’t fun.

1 Like

1 Like

y u do dis

1 Like

In a similar vein, … should coerce bools to strings so I don’t ever see this when I’m debugging and already mad that something isn’t working the way it should be.

4 Likes

Why are you concatenating that? You can just do print(“game pad:”, UIS.GamePadEnabled) and get what you want.

1 Like

If I have a GUI label that displays the status of something, given that the variable status is a boolean, I might do something like this:

label.Text = "Enabled: "…status

support

1 Like

No support. You can already do that with HTTPService:JSONEncode(table) (which was mentioned in the OP). Table.stringify would not make the slightest of differences.

That’s fair. I’ll add that one for our internal review. Though my previous comment is a solution to being unable to print booleans if it’s something he needs to do right now.

1 Like

There’s table.concat(), however it doesn’t work with non-numeric keys.

Even if it did, it’d pretty much be the same behavior is JSONEncode and not help in OP’s case (but the feature on the Trello card would)

still support
I’m against modifying Lua’s internals. I want it to stay vanilla. Library modifications are fine though as they are like addons.

2 Likes

If you are going through with this, then it would be nice to make it work properly for all types (except userdata) that cannot be properly concatenated yet: tables, bools, and nil (“Test” … nil fails for similar reasons, could be stringified to “nil” by …).

still no support

stringify is a pointless name change that can already be accomplished with existing methods.


[quote="sparker22, post:51, topic:24789"] I'm against modifying Lua's internals. [/quote] That's interesting, considering you were in favor of modifying "table" to add stringify.

I didn’t know print() could take a variable number of arguments.

If typing “print(” offered some form of autocomplete then I would have known that was the way to do it in Lua.

But we had a discussion just the other day that print does take a tuple, so you should have known by now… :sweat_smile: