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
Concat strings using '+' crashes Love on my Mac
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 6
- Joined: Thu Oct 28, 2010 5:31 pm
Re: Concat strings using '+' crashes Love on my Mac
That's because you're calling the __add metamethod, which is nil.
Addingbefore your code will fix it.
Adding
Code: Select all
getmetatable("").__add=function(s1,s2) return s1..s2 end
Hello, I am not dead.
-
- Prole
- Posts: 6
- Joined: Thu Oct 28, 2010 5:31 pm
Re: Concat strings using '+' crashes Love on my Mac
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...
Re: Concat strings using '+' crashes Love on my Mac
I saw your post after I logged in.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...
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.
- 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
It's not a bug, it's a missing feature!
Re: Concat strings using '+' crashes Love on my Mac
Lol.bartbes wrote:It's not a bug, it's a missing feature!
Hello, I am not dead.
Re: Concat strings using '+' crashes Love on my Mac
Whoa whoa whoa whoa whoa. Hang on.
First off, zac352: No. You're wrong. I just actually tried this myself, with the following code:
And got the following:
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.
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
So. Attempting to use + errors properly. The crash, then is due to something else.The Blue Screen of LÖVE wrote:main.lua:2: attempt to perform arithmetic on a string value
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.
Re: Concat strings using '+' crashes Love on my Mac
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.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:And got the following:Code: Select all
function love.draw() love.graphics.print("hi "+"world", 400, 300) end
So. Attempting to use + errors properly. The crash, then is due to something else.The Blue Screen of LÖVE wrote:main.lua:2: attempt to perform arithmetic on a string value
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.
Edit:
Put this code in the online Lua demo:
Code: Select all
getmetatable("").__add=function(s1,s2) return s1..s2 end
print("Hello"+" "+"World")
Last edited by zac352 on Tue Nov 02, 2010 9:32 pm, edited 1 time in total.
Hello, I am not dead.
- 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
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.
EDIT: To clarify, that is not making lua do concat with +, but rather the (lack of) errors.
Re: Concat strings using '+' crashes Love on my Mac
While, what ever happened to the unusual microsoft C++ runtime library errors I get when I call love.physics.newWorld?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.
Hello, I am not dead.
Who is online
Users browsing this forum: Google [Bot] and 10 guests