Docunext


Lua Strings

October 13th, 2009

I had to work with strings in Lua today, and found that there was some significant differences between 5.0 and 5.1.

The Lua Wiki was quite helpful, except I found one code snibbet which didn't work for me, it was missing "then" at the end of line two in after the if statement:

function url_encode(str)
  if (str) then
    str = string.gsub (str, "\n", "\r\n")
    str = string.gsub (str, "([^%w ])",
        function (c) return string.format ("%%%02X", string.byte(c)) end)
    str = string.gsub (str, " ", "+")
  end
  return str
end
local hi = url_encode("blah")
print(hi)
Yearly Indexes: 2003 2004 2006 2007 2008 2009 2010 2011 2012 2013 2015 2019 2020 2022