My understanding is that LuaJIT uses the Lua 5.1 syntax. In Lua 5.1, the 'arg' feature was removed from the language.
However, the following code works.
// test.lua
local function foo()
for k,v in pairs(arg) do
print(k .. " " .. v)
end
end
foo()
I would expect arg
to be nil, but it exists and is doing the Lua 5.0 functionality.
Running resty test.lua hello world
results in:
0 test.lua
1 hello
2 world
-1 /usr/local/bin/resty
Why does this work? Are there exceptions to the 5.1 syntax that Openresty and LuaJIT can use?
You're mixing two different things.
The arg
table you see here is not a "deprecated Lua feature". It's a table of arguments given to Lua interpreter, explicitly pushed to the global arg
variable by the interpreter, and it's still there in the latest Lua and LuaJIT versions.
The feature you've heard was removed - that's about replacing implicit arg
parameter with vararg expression in vararg functions. I.e. the extra arguments to functions now available through ...
syntax, and not as a table of collected values through implicit arg
parameter.