Lua string to int

lua
David Gomes picture David Gomes · Jun 9, 2012 · Viewed 254.9k times · Source

How can I convert a string to an integer in Lua?

I have a string like this:

a = "10"

I would like it to be converted to 10, the number.

Answer

Nicol Bolas picture Nicol Bolas · Jun 9, 2012

Use the tonumber function. As in a = tonumber("10").