a = 2
b = '3'
print('a is '..type(a))
print('b is '..type(b))
-- result
-- a is number
-- b is string
print(a+b)
-- Error:[string "a = 2..."]:10: attempt to perform arithmetic on a string value (global 'b')
-- because try to make math addtion a (number) + b (string)
-- convert b value from string to number
b=tonumber(b)
-- test
print(a+b)
-- result = 5
function ansiToUtf8(String) : string
Converts a string in Ansi encoding to UTF8
ANSI stands for American National Standards Institute.
The ANSI character set includes the standard ASCII character set (values 0 to 127),
plus an extended character set (values 128 to 255).
The ANSI character set is used by Windows end refers to the codepage 1252 known as "Latin 1 Windows"
should be = 5 because Lua will automatically translate this b = '3' as a number, but the error appears on my CE 6.8.3 (Lua 5.3) as shown above. I tried again on my Lua 5.3 for window console, the code 2 + '3' give result 5.0.
I have tested again CE 6.8.3 and test the same code (without any other line code) and the result is 5.0.
Back to the topic which asked for, here another reference:
Code:
> = 100 == "100"
false
> = 100 ~= "hello"
true
> = 100 ~= {}
true
> = 100 == tonumber("100")
true
> = 100 <= "100"
stdin:1: attempt to compare number with string
stack traceback:
stdin:1: in main chunk
[C]: ?
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum