I need some help on parsing the Command Line for a lua file. I am executing a lua file and that lua file has a command "dofile(2nd.lua-file)", but, I want to pass some argument to this 2nd lua file through this 1st lua file.
example- a.lua has dofile("b.lua"), and now I have to pass some argument to b.lua through this a.lua and how can I do this.
To pass arguments into Lua, the script name and arguments must be enclosed within double quotes. The arguments are stored within the arg variable in Lua, which is a table of strings.
Lua offers a higher-level function to load and run libraries, called require . Roughly, require does the same job as dofile , but with two important differences. First, require searches for the file in a path; second, require controls whether a file has already been run to avoid duplicating the work.
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 ...
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With