title: Example usage where Lua fits much better than C/C++
body: <p>I'm currently embedding Lua and using it as a glorified intelligent config file. However, I think I'm missing something since people rave about the uses of Lua.</p>
  
  <p>For example, I can easily explain why you might use shell scripting instead of C by showing this example (admittedly , boost regexp is overkill):</p>
  
  <pre><code>#include &lt;dirent.h&gt; 
  #include &lt;stdio.h&gt; 
  #include &lt;boost/regex.hpp&gt;
  
  int main(int argc, char * argv[]) {
      DIR           *d;
      struct dirent *dir;
      boost::regex re(".*\\.cpp$");
      if (argc==2) d = opendir(argv[1]); else d = opendir(".");
  if (d) {
      while ((dir = readdir(d)) != NULL) {
              if (boost::regex_match(dir-&gt;d_name, re)) printf("%s\n", dir-&gt;d_name);
      }
  
      closedir(d);
  }
  
  return(0);
  </code></pre>
  
  <p>and compare it to:</p>
  
  <pre><code>for foo in *.cpp; do echo $foo; done;
  </code></pre>
  
  <p>Are there any examples that you can give in Lua which can make it 'click' for me? </p>
  
  <p>EDIT: Maybe my problem is that I don't know Lua well enough yet to use it fluently as I'm finding it easier to write C code.</p>
  
  <p>EDIT2:</p>
  
  <p>One example is a toy factorial program in C++ and Lua:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  int fact (int n){
      if (n==0) return 1; else
      return (n*fact(n-1));
  }
  
  int main (){
      int input;
      using namespace std;
      cout &lt;&lt; "Enter a number: " ;
      cin &gt;&gt; input;
      cout &lt;&lt; "factorial: " &lt;&lt; fact(input) &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>Lua:</p>
  
  <pre><code>function fact (n)
      if n==0 then
          return 1
      else 
          return n * (fact(n-1))
      end
  end
  
  print ("enter a number")
  a = io.read("*number")
  print ("Factorial: ",fact(a))
  </code></pre>
  
  <p>Here, the programs look alike, but there's clearly some cruft in the include, namespace and main() declarations you can get rid of. Also remove variable declarations and strong typing.</p>
  
  <p>Now are people saying this is the advantage which adds up over a larger program, or is there more to it? This doesn't stand out in the same way as the bash example.</p>