Concat strings using '+' crashes Love on my Mac

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
patrickjcollins
Prole
Posts: 6
Joined: Thu Oct 28, 2010 5:31 pm

Concat strings using '+' crashes Love on my Mac

Post by patrickjcollins »

Hi chaps,

If I try to concat two strings with the '+' plus operator Love crashes on my MacBook. I've since learnt that concatenations are done with the ".." operator. RTFM and all that. Anyway, thus far Love has been presenting me clear and precise error messages, this crash was a bit of a surprise and took some hunting to figure out. Has anyone experienced the same thing?

Patrick
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: Concat strings using '+' crashes Love on my Mac

Post by zac352 »

That's because you're calling the __add metamethod, which is nil.

Adding

Code: Select all

getmetatable("").__add=function(s1,s2) return s1..s2 end
before your code will fix it. :P
Hello, I am not dead.
patrickjcollins
Prole
Posts: 6
Joined: Thu Oct 28, 2010 5:31 pm

Re: Concat strings using '+' crashes Love on my Mac

Post by patrickjcollins »

Wow, that was a fast reply. But is it normal that Love should crash without showing an error message? I have another crash going on at the moment, although it's not due to string concatenation, must be something else. So it's block comments and debug messages again...
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: Concat strings using '+' crashes Love on my Mac

Post by zac352 »

patrickjcollins wrote:Wow, that was a fast reply. But is it normal that Love should crash without showing an error message? I have another crash going on at the moment, although it's not due to string concatenation, must be something else. So it's block comments and debug messages again...
I saw your post after I logged in. :P

Uh... I've gotten crashes from the physics library. I think it may be some sort of bug in Love. Someone should probably look into that...

[cue post with link to bug]
Hello, I am not dead.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Concat strings using '+' crashes Love on my Mac

Post by bartbes »

It's not a bug, it's a missing feature!
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: Concat strings using '+' crashes Love on my Mac

Post by zac352 »

bartbes wrote:It's not a bug, it's a missing feature!
Lol.
Hello, I am not dead.
User avatar
bmelts
Party member
Posts: 380
Joined: Fri Jan 30, 2009 3:16 am
Location: Wiscönsin
Contact:

Re: Concat strings using '+' crashes Love on my Mac

Post by bmelts »

Whoa whoa whoa whoa whoa. Hang on.

First off, zac352: No. You're wrong. I just actually tried this myself, with the following code:

Code: Select all

function love.draw()
        love.graphics.print("hi "+"world", 400, 300)
end
And got the following:
The Blue Screen of LÖVE wrote:main.lua:2: attempt to perform arithmetic on a string value
So. Attempting to use + errors properly. The crash, then is due to something else.

Here's a thought. Are you:
a) using LÖVE 0.6.2 (or older)
b) setting some variable named "debug" somewhere in your code

If both of those are true, that would explain the mysterious crashing - debug is a built-in Lua table, and LÖVE uses it to display the error screen; thus, trying to use it as a variable of your own means LÖVE can't call the debug code it needs, and thus the game just crashes. (For the record, this is fixed in the 0.7.0 beta.)

If the above is not the case... post your code, it'd make it a lot easier to debug.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: Concat strings using '+' crashes Love on my Mac

Post by zac352 »

anjo wrote:Whoa whoa whoa whoa whoa. Hang on.

First off, zac352: No. You're wrong. I just actually tried this myself, with the following code:

Code: Select all

function love.draw()
        love.graphics.print("hi "+"world", 400, 300)
end
And got the following:
The Blue Screen of LÖVE wrote:main.lua:2: attempt to perform arithmetic on a string value
So. Attempting to use + errors properly. The crash, then is due to something else.

Here's a thought. Are you:
a) using LÖVE 0.6.2 (or older)
b) setting some variable named "debug" somewhere in your code

If both of those are true, that would explain the mysterious crashing - debug is a built-in Lua table, and LÖVE uses it to display the error screen; thus, trying to use it as a variable of your own means LÖVE can't call the debug code it needs, and thus the game just crashes. (For the record, this is fixed in the 0.7.0 beta.)

If the above is not the case... post your code, it'd make it a lot easier to debug.
Last time I checked, setting a metamethod in any string sets that metamethod for all strings... Wait, it does. So, either you messed up, or we just found another missing feature. ;)

Edit:
Put this code in the online Lua demo:

Code: Select all

getmetatable("").__add=function(s1,s2) return s1..s2 end

print("Hello"+" "+"World")
Which is here, if you fail to find it.
Last edited by zac352 on Tue Nov 02, 2010 9:32 pm, edited 1 time in total.
Hello, I am not dead.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Concat strings using '+' crashes Love on my Mac

Post by bartbes »

It works, but it's still crap. Now get back on topic.

EDIT: To clarify, that is not making lua do concat with +, but rather the (lack of) errors.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: Concat strings using '+' crashes Love on my Mac

Post by zac352 »

bartbes wrote:It works, but it's still crap. Now get back on topic.

EDIT: To clarify, that is not making lua do concat with +, but rather the (lack of) errors.
While, what ever happened to the unusual microsoft C++ runtime library errors I get when I call love.physics.newWorld? :roll:
Hello, I am not dead.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 10 guests