title: Lua: Functions with Multiple Returns
body: <p>For some reason, I'm having issues wrapping my head around the appropriate way to use parameters in a function, and later call for that function and return the correct parameters.  If I wanted to use a function to find out the type of shape used.  This shape contains data right after the shape abbreviation, such as Sq105428, that I would like to use. Quick Ex:</p>
  
  <pre><code>function Shape(...) -- can I use "..." or should I put "Type, Shape_data, Shape_side" inside?
      Shapes = {["Tri"] = 3, ["Sq"] = 4, ["Po"] = 5, ["Hex"] = 6}
          for k,v in pairs (Shapes) do
              Type = string.match(input, k..".*")
                  if Type == k then
                      Shape_data = string.match(input,Type.."(.*)")
                      Shape_side = v
                  end
          end
          return Type, Shape_data, Shape_side -- can I call for these later in my code?
  end
  </code></pre>
  
  <p>Later, I would call for the variables returned and use them.  I'm having problems understanding how to properly call for those variables that were returned.  In my code, I would like to take the three variables and use them throughout the code.  How would I properly call for them?</p>
  
  <p>I understand that:</p>
  
  <pre><code>function f() body end  ==  f = function() body end -- pg 15 PIL and helps me to understand
  </code></pre>
  
  <p>I also understand how to properly use mathematical functions such as:</p>
  
  <pre><code>function exp (x)
      print x^2
  end
  
  print exp(4) -- yields 16
  </code></pre>
  
  <p>But what is the appropriate way to call for my example if I want to use the three variables at different points of the code?  I'm having problems completely understanding how to properly construct the function call and call for that later.  Is it as easy as:</p>
  
  <pre><code>Example = math.floor(math.pi * Shape(Shape_side) + 0.5) -- is this ok?
  </code></pre>
  
  <p>I appreciate the help.</p>