1

I am passing arguments to a Lua script and retrieving them using:

local arg1, arg2 = ...

Now I'd like to use a different syntax, with free ordering, such that I can call:

./myscript.lua arg1=val1 arg2=val2

so I'm trying something like:

args = ...
params = {}

for i, k in pairs(args) do
  p, v = split(a, "=")
  params[p] = v
end

which doesn't work because args only gets the value of the first argument.

How can I retrieve all the arguments passed to the script in one go?

Note: the script is executed from C using lua_pcall.

0

1 Answer 1

2

Assign it with {...} like this:

args = {...}
params = {}

for i, k in ipairs(args) do
  print(i, k)
end

In fact, args is not needed:

for i, k in ipairs{...} do
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.