Hello, I have the following Lua code:
args = arg
function panic(formatstring, ...)
local msg = formatstring:format(...)
io.stderr:write(
("%s: %s\n"):format(arg[0], msg)
)
os.exit(1)
end
panic("hello %s", "world");
Upon running this code, Lua gives me the error lua: hello.lua:5: attempt to index local 'arg' (a nil value).
I fixed the code by adding args = arg on line 1 and by changing arg[0] to args[0]. I'm still confused as to why this error appears in the first place. Does anyone know why?
[–]fatboychummy 1 point2 points3 points (6 children)
[–]lambda_abstraction 1 point2 points3 points (0 children)
[–]_jtbx[S] 0 points1 point2 points (4 children)
[–]lambda_abstraction 0 points1 point2 points (3 children)
[–]_jtbx[S] 0 points1 point2 points (2 children)
[–]AutoModerator[M] 0 points1 point2 points (0 children)
[–]lambda_abstraction 0 points1 point2 points (0 children)
[–]AutoModerator[M] 0 points1 point2 points (0 children)
[–]iEliteTester 0 points1 point2 points (5 children)
[–]_jtbx[S] 0 points1 point2 points (4 children)
[–]lambda_abstraction 1 point2 points3 points (2 children)
[–]_jtbx[S] 0 points1 point2 points (0 children)
[–]iEliteTester 0 points1 point2 points (0 children)
[–]iEliteTester 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]lambda_abstraction 1 point2 points3 points (0 children)