lua-users home
lua-l archive

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

I am one of those who don't know upvalues and closure:-)
However, I'd like to find a tutorial about that. The manual
seems to be not clear on that. Thanks for any help.
----- Original Message -----
Sent: Monday, June 02, 2003 5:47 AM
Subject: one more little thing about upvalues

In lua book (BTW, a question to Roberto: how high is the finishing of THE BOOK in your priority list? ;-) there is an interesting example of using upvalues in Lua4:
sin = function (x)
  return %sin(x*180/PI)
This thing is not directly reproducible in Lua5, right? The way to do this in 5.0 I can think of is this:
local old_sin = sin
sin = function (x)
  return old_sin(x*math.pi/180) -- updated to Lua5 specifics: convert back to accepting degrees ;-)
Is this right? Is this the only way? Will it work just the same? (I tested it to some expent, it produced similar result on my test script for Lua4 and Lua5 versions).
P.S. I wonder if this discussion of upvalues os of use to anybody (even me): those who use closure know what it is, those who don't know - well, then just do not use them 8-)