[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How access local variables with load*() functions
- From: "Aaron Brown" <aaron-lua@...>
- Date: Thu, 8 Sep 2005 16:39:45 -0400
Mildred wrote:
> I just realized that I can't access locals variables with
> aly load*() function (load, loadfile, loadstring, dofile)
> Is that normal ?
Yes.
> 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
--
Aaron