lua-users home
lua-l archive

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


Frank Meier-Dörnberg schrieb:
Leo Razoumov schrieb:
On 2010-01-09, steve donovan <steve.j.donovan@gmail.com> wrote:
 (BTW, a safer 5.2 idom is:

 local loadstring = loadstring
 in {x = 1, y = 10} do fn = loadstring 'return x + y' end

 Given that loadstring is potentially a nasty function in a sandbox)

 steve d.

Can one do the following instead?

local fn = loadstring 'return x + y' --first compile the chunk for future use

in {x = 1, y = 10, print=print} do print(fn()) end  -- 11
in {x = 2, y = 20, print=print} do print(fn()) end  -- 22

--Leo--

Potentially I totally missed the point, but if isolation is the problem, what is with (untestet):

local fn = loadstring ' function(env) do' .. 'return x + y' .. 'end'
Ehm, I mean:

local fn = loadstring ' function(env) do in env do ' .. 'return x + y' .. ' end end'

in {} do print(fn{x = 1, y = 10, print=print}) end -- 11
in {} do print(fn{x = 2, y = 20, print=print}) end -- 22

?
Frank