[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How access local variables with load*() functions
- From: Peter Shook <peter.shook.engineer@...>
- Date: Thu, 8 Sep 2005 21:53:27 -0400
On 9/8/05, Mildred <ml.mildred593@online.fr> wrote:
> I just realized that I can't access locals variables with aly load*() function (load, loadfile, loadstring, dofile)
> What can I do to access those locals variables ?
In Lua 5.1, loadstring returns a function that you can pass arguments
to and they will be placed in the magic ... list like so:
local fun = loadstring[[
print 'second'
local x, y, z = ...
print('x','y','z')
print(x, y, z)
]]
local a, b, c = 'one', 'two', 'three'
print 'first'
print('a','b','c')
print(a, b, c)
assert(fun)(a, b, c)
The script above will output the following:
first
a b c
one two three
second
x y z
one two three
Cheers,
- Peter Shook