lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, Aug 2, 2016 at 3:12 PM, Marc Balmer <marc@msys.ch> wrote:
>> Am 02.08.2016 um 20:37 schrieb Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>:
>>
>>> I assume that I have to set _ENV for each chunk that possibly runs
>>> during template rendering (it can be many, and the idea is to call
>>> them repeatedly using different data tables). So this would mean to
>>> fixup _ENV for each chunk everytime the render() function is called?
>>
>> When you convert templates to Lua code, add this line at the top of each script:
>>       local _ENV = ...
>>
>> (That's three dots as in varargs.)
>> Then you can run each script passing a suitable table as its env at run time.
>>
>
> I will try that.  It has been proposed to me in private mail as well.

You might also look at this custom loader used in the Nmap Scripting
Engine that allows repeatedly executing a chunk with a new environment
each time:

https://github.com/nmap/nmap/blob/master/nse_main.lua#L242-L256

-- 
Patrick Donnelly