lua-users home
lua-l archive

Passing arguments to a chunk?

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


Using loadfile() I can load a Lua chunk and assign it to a function:
env = {}
script = loadfile('test.lua', 'r', env)
Then using pcall() I can execute it:
pcall(script)
So far so good, but is there a way to pass an argument to a chunk? Using pcall, I can pass arguments like this
args = {}
args.data = 'Hello, world'
pcall(script, args)
But how can I access "args" from within the Lua chunk "test.lua"?

AltStyle によって変換されたページ (->オリジナル) /