ret = function()
return x
end
debug.setupvalue(ret , 1 , {x = 90})
love.errhand( ret() )
shows nil when it should return 90
this workes in the lua console on mac.
thanks
upvalues not working
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: upvalues not working
In your code `x` is not an upvalue, it's a global variable. Also you are using `debug.setupvalue` wrong. If you want to return 90 it should be debug.setupvalue(ret, 1, 90).
If x is supposed to be an upvalue it needs to be local and bound to another scope, here's a working example:
Code: Select all
function makeClosure()
local x
return function()
return x
end
end
ret = makeClosure()
print(ret()) -- prints nil
debug.setupvalue(ret, 1, 90)
print(ret()) -- prints 90
- zorg
- Party member
- Posts: 3470
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: upvalues not working
That was also about the same answer you got on the issue tracker.
(Also, i'm pretty sure the line love.errhand( ret() ) doesn't work on the (plain) lua console itself, since it's something that löve defines...)
Nice website, by the way.
(Also, i'm pretty sure the line love.errhand( ret() ) doesn't work on the (plain) lua console itself, since it's something that löve defines...)
Nice website, by the way.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: upvalues not working
Thank you.
ps. I used print in console not love.errhand()
ps. I used print in console not love.errhand()
Who is online
Users browsing this forum: Bing [Bot], Google [Bot], Semrush [Bot] and 5 guests