title: Defining a function within a loop using loadstring with Lua 5.1
body: <p>I'm currently trying to define a function using a combination of concatenation, loadstring, and a for loop.</p>
  
  <p>This is the kind of thing I have currently:</p>
  
  <pre><code>&gt; for f=1,8 do
  loadstring("function f" .. f .. " () print('" .. f .. "') end")
  end
  &gt; f1()
  stdin:1: attempt to call global 'f1' (a nil value)
  stack traceback:
      stdin:1: in main chunk
      [C]: ?
  </code></pre>
  
  <p>The function evaluates a set of chunks in the form of: 'function f () print() end'. However, as you can see, it doesn't seem to save the function into the variables f1-f8 correctly.</p>