lua-users home
lua-l archive

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

On 9/8/05, Mildred <> 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)

local a, b, c = 'one', 'two', 'three'

print 'first'
print(a, b, c)
assert(fun)(a, b, c)

The script above will output the following:

a       b       c
one     two     three
x       y       z
one     two     three


- Peter Shook