lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On 27/03/15 06:05 PM, Sean Conner wrote:
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 ... )


debug.upvaluejoin(meta.print, 1, function() return meta end, 1) -- requires meta to be a local, but w/e, you'll figure it out

--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.