lua-users home
lua-l archive

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

Mildred wrote:

> I just realized that I can't access locals variables with
> aly load*() function (load, loadfile, loadstring, dofile)

> Is that normal ?


> Why ?

Because strings (since they are a chunk of data that can be
passed around anywhere inside a program) are not considered
to be lexically nested within any part of the program, and
local variables are lexically scoped.

> What can I do to access those locals variables ?

Here's one way (that may not be appropriate for what you
want to do):

Lua 5.0.2  Copyright (C) 1994-2004 Tecgraf, PUC-Rio
> do
>>   local aa = "bb"
>>   loadstring("print('aa = ', " .. string.format("%q", aa) .. ")")()
>> end
aa =    bb