Reputation: 1
Im new into lua, I have this code :
a="1"
b="2"
c=
Is it possible to somehow define c as a+b?
Upvotes: 0
Views: 260
Reputation: 28950
What do you mean with a+b
?
If you want to add the numbers in both strings and get a number simply do
c = a + b
This implicitly does
c = tonumber(a) + tonumber(b)
This only works if a and b represent numbers! Lua will convert the strings to numbers prior to calcuating the sum.
If you want the sum as a string simply do
c = tostring(a+b)
If you want to concatenate both strings use the concatenation operator ..
c = a .. b
This will result in c
being "12"
Upvotes: 3
Reputation: 508
Yes. With:
c = a + b
The two values will be added, and 3.0
will be stored in c
at runtime.
Upvotes: 0