Lua Table of Strings to Table of Integers

Viewed 57

I am completely new to lua and I would like some help. I have a Table of numbers in string format. How can I change them to integers? Is there a function that can do this. Or what is the best way.

input = {"1", "2", "3"}

output = {1, 2, 3}

For now I found only function tonumber which changes a string to number. So I could solve this with a loop.

1 Answers
local input = {"1", "2", "3"}
local output = {}

for i = 1, #input do
  output[i] = tonumber(input[i])
end

or

for i,v in ipairs(input) do
  output[i] = tonumber(v)
end
Related