title: local variable cannot be seen in a closure across the file?
body: <p>Suppose I have the following two Lua files:</p>
  
  <p>In <code>a.lua</code>:</p>
  
  <pre><code>local x = 5
  f = dofile'b.lua'
  f()
  </code></pre>
  
  <p>In <code>b.lua</code>:</p>
  
  <pre><code>local fun = function()
    print(x)
  end
  return fun
  </code></pre>
  
  <p>Then if I run <code>luajit a.lua</code> in shell it prints <code>nil</code> since <code>x</code> cannot be seen in the function defined in <code>b.lua</code>. The expected printing should be <code>5</code>. However if I put everything in a single file then it's exactly what I want:</p>
  
  <p>In <code>aa.lua</code>:</p>
  
  <pre><code>local x = 5
  local f = function()
    print(x)
  end
  f()
  </code></pre>
  
  <p>Run <code>luajit aa.lua</code> it prints <code>5</code>.</p>
  
  <p>So why <code>x</code> cannot be seen in the first case?</p>