The following script fails:
meta =
{
io = io,
tostring = tostring,
select = select,
print = function(...)
io.stdout:write("HERE I AM, JH ... ")
for i = 1 , select('#',...) do
io.stdout:write(tostring(select(i,...)),"\t")
end
io.stdout:write("\n")
end
}
print(debug.setupvalue(meta.print,1,meta))
name,env = debug.getupvalue(meta.print,1) -- line 16
When I run it with Lua 5.3, I get:
_ENV
lua-53: /tmp/t.lua:16: attempt to index a nil value (global 'debug')
stack traceback:
/tmp/t.lua:16: in main chunk
[C]: in ?
I'm curious---what am I doing wrong in the first case?
-spc (And for the curious---this is a testcase for some code I'm playing
around with ... )