How can I pass parameters to a Lua file when loading it from another Lua file?
An easy way:
Command and output:
C:\LUAWORK\Estudio-Tut>lua -e "a=2 b=3 c=4 dofile(‘argu.lua’)"
2 3 4
4 6 8
File 1, argu.lua:
print (a , b ,c)
a=2*a
b=2*b
c=2*c
dofile ( ‘otro.lua’)
File 2, otro.lua:
print (a ,b, c)
Using -e "……." I set globals in the call to any chain of modules
Try this. In file `a.lua':
assert(loadfile("b.lua"))(10,20,30)
In file b.lua
:
local a,b,c=...
or
local arg={...}
The arguments to b.lua
are received as varargs, hence the ...
.