Is it possible to perform arithmetic on multiple values in Lua. I am using Lua for windows 5.1.4.
Currently I have to put the multiple values into a table and then unpack them, and I would like to be able to skip that step.
Is it possible.
Here is what I currently have:
function numsToStr(...)
local nums = {}
for i,v in ipairs({...}) do
nums[i] = v + string.byte('A') - 1
end
return string.char(unpack(nums))
end
What I want is to be able to do this
function numsToStr(...)
return string.char(...+string.byte('A')-1)
end
No, it is not possible to do arithmetic on multiple values in Lua.
It's not possible to do "directly", but you can implement "map" function, similar to what you've done. Some relevant resources: Short anonymous functions, thread on Perl-like map/grep functions, and map and other functions. Also take a look at list comprehensions in Penlight.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With