local t = {} local template = [[ local f do local result function f() if not result then result = f() + f() end return result end end ]] t[1] = [[ local f1 f1 = function() return 1 end ]] t[2] = [[ local f2 f2 = function() return 1 end ]] for i = 3, 199 do t[i] = template:gsub("<([^>]+)>", function(s) local c = assert(loadstring('return '..s), 'could not compile: '..s) setfenv(c, { i = i }) return c() end) end t[200] = [[ print("5th fibonacci number is", f5()) print("10th fibonacci number is", f10()) print("199th fibonacci number is", f199()) ]] local s = table.concat(t) print(s) f = loadstring(s) f()