Make concatenate operator ".." work on tables

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:

table is a library though which I said is fine.[quote=“sparker22, post:51, topic:24789”]
Library modifications are fine though as they are like addons.
[/quote]

I don’t really care as long as the internals aren’t touched outside of library additions.

Context help will tell you this if you highlight ‘print’ in a script. Alternatively, it’s also on the wiki. That being said, Intellisense is a work in progress.

Yes as you can see, getting debug output is a real pain point for me.

Still it’s kind of odd that we have to invoke HttpService to turn a table into a string though? Like if I’m just printing output, it’s weird to see HttpService there even though I’m doing nothing network-related. And if the concatenate operator will be able to do this, we’d still need to say something like

someString = "" .. someTable

If we really don’t want to use HttpService. If we had a method in the table library that would stringify tables in the same way as the concatenate operator will (if this goes through at least), then we won’t need to do any ugly things with HttpService or the line I just put.

EDIT: thinking about it, if this change is made then probably tostring will have to be changed so that it properly prints tables. So this may not be relevant then anymore.

I just want my code to look elegant and understandable.

Lua code tends to look like barf.

I don’t agree with that. I think if done properly it looks good.

I’ve been thinking about it since my posts yesterday, I was a bit hesitant at first because it’s quite a basic Lua operator that you want to change the behaviour of, but it will probably be beneficial and won’t break existing code. So I’m in favour of the change now.

If this is happening though, I would really like if this were the case (as I mentioned):

  • Apply it to all types that cannot currently be concatenated properly, not just to table (table, nil, booleans, userdata (if a tostring method is available for it))
  • Make tostring print tables in the same way as they are concatenated, so we don’t need to use HttpService anymore if we just want to catch the stringified table into a variable. HttpService:JSONEncode(someTable) looks less clean than tostring(someTable), especially in code that doesn’t even have any networking.