title: Running Lua scripts line per line
body: <p>I'm making a game where you code your own robot using Lua inside the game. I'm using the C# Lua library called <a href="http://nlua.org/" rel="nofollow">NLua</a>, which basically works just like the offical C library.</p>
  
  <p>If the user enters the following code:</p>
  
  <pre><code>for i=0,10 do -- Repeat 10 times
      if (robot:check_clear(0.1)) then -- Check if clear up to 10cm in front
          robot:go_foward(0.1) -- Go foward 10cm
      else then
          robot:turn_right(45) -- Turn 45 degrees
      end
  end
  </code></pre>
  
  <p>I want it to run the entire code 10 times, as you can see. It will move on to check robot:check_clear(), let's say it returns false. So it will now run robot:turn_right(45) and wait for the action to finish, because rotation might take 3 seconds or so. Same with go_forward(0.1). How would I make it wait before moving on?</p>
  
  <p>Right now I use <code>lua.DoString(code);</code>  to execute all of the code. The problem is that it doesn't wait before moving on.</p>
  
  <p>The <em>robot</em> in the code refers to a C# class I have called LRobot. It is assigned by doing this <code>lua["robot"] = new LRobot();</code></p>
  
  <p>I'm a bit of a newcommer to Lua and the Lua C/C# library, so I'd be thankful for detailed answers. I don't want someone to code this for me, just want to know of key commands and how to structure it all.</p>
  
  <p>Thanks in advance!</p>