stevedonovan/Penlight — Issue #20: Local variable scope bug using templates
Author: KINFOO
Created: 2012-01-15 19:33:28+00:00
State: open

Hi,
I'm using your template library. I notice a strange behavior using a variable defined in a tamplate. Here is a sample:

package.path = '/d/penlight/lua/?.lua;' .. package.path
local generator = require 'pl.template'
local var = [[
# local tab = {}
# for i = 1,3 do
$(i)
#	tab [ #tab ] = i
#	tab [ #tab ] = ' '
# end
$(concat( tab ))
]]
local content = {
concat = table.concat
}
print(generator.substitute(var, content))

Here is the output of this code:

% lua local.lua
1
2
3

The _i_ local variable defined in the for statement is accessible but not the _tab_ variable defined with local satement.
Is it a bug or am I doing it wrong?
Cheers