Cast from string to number in a LUA script does not happen when comparing and argument with a number #3736

Open
prochan2 opened this Issue Jan 9, 2017 · 1 comment

Projects

None yet

3 participants

@prochan2
prochan2 commented Jan 9, 2017
> eval "if ARGV[1] > 0 then return ARGV[1] .. ' > 0' else return ARGV[1] .. ' <= 0' end" 0 1
(error) ERR Error running script (call to f_288c501a9193b9942600e86b1d35426982e4a58e): @user_script:1: user_script:1: attempt to compare number with string

> eval "if ARGV[1] + 0 > 0 then return ARGV[1] .. ' > 0' else return ARGV[1] .. ' <= 0' end" 0 1
"1 > 0"

See the left side of the comparison.

@itamarhaber
Contributor
itamarhaber commented Jan 10, 2017 edited

@prochan2 I'm not sure that I understand the issue - this behavior is standard Lua. The ARGV table contains strings - if you want to convert a string to a number, use Lua's tonumber() function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment