Empty variable check


I'm just learning lua, this is my first script with it. How can I check to see if a variable is empty or has something like a line feed in it?

Best Solution

You can check whether the value is nil:

if emptyVar == nil then
   -- Some code

Since nil is interpreted as false, you can also write the following:

if not emptyVar then
   -- Some code

(that is, unless you want to check boolean values ;) )

As for the linebreak: You can use the string.match function for this:

local var1, var2 = "some string", "some\nstring with linebreaks"
if string.match(var1, "\n") then print("var1 has linebreaks!") end
if string.match(var2, "\n") then print("var2 has linebreaks!") end