Page 1 of 1
Lua 5.2, almost here
Posted: Thu Dec 08, 2011 12:53 am
by ishkabible
so Lua 5.2 is almost here and it will hopefully "change the way the way you love" what are you looking forward too in 5.2? what do not like?
something i don't like: in Lua 5.2, the goto statement was added...bleh, why?!
Re: Lua 5.2, almost here
Posted: Thu Dec 08, 2011 3:58 am
by Ensayia
http://www.lua.org/work/doc/
A little over halfway down the page is the complete change list. There's a note about Lua getting a new bitops library. I have not done much with them but hear that Lua needs a little extra support to do them right, Hopefully this is good news. The rest is sort of over my head.
Re: Lua 5.2, almost here
Posted: Thu Dec 08, 2011 4:28 am
by TechnoCat
"new lexical scheme for globals"
I don't like the sound of that.
Re: Lua 5.2, almost here
Posted: Thu Dec 08, 2011 4:39 am
by Taehl
"new library for bitwise operations"
Woohoo!
Re: Lua 5.2, almost here
Posted: Thu Dec 08, 2011 5:10 am
by Jasoco
TechnoCat wrote:"new lexical scheme for globals"
I don't like the sound of that.
What does it mean?
Re: Lua 5.2, almost here
Posted: Thu Dec 08, 2011 6:10 am
by Xgoff
Jasoco wrote:TechnoCat wrote:"new lexical scheme for globals"
I don't like the sound of that.
What does it mean?
a function environment is now an upvalue called _ENV rather than some hidden value you use getfenv/setfenv for
... of course some people aren't very happy about this since the latter two functions are now deprecated and therefore breaks existing sandboxes (and unlike setfenv you can't just change some function's environment given a stack offset or the function reference anymore)
Re: Lua 5.2, almost here
Posted: Thu Dec 08, 2011 10:27 am
by kikito
The best page I could find explaining the changes is this one:
http://www.corsix.org/content/look-lua-52-work3
The "global memory change" can be explained like this: if you don't use
setfenv or
getfenv, you don't need to worry about it - But you might want to check how you use
_G, and consider using _ENV instead.
Longer explanation: there is a new guy in town called _ENV, and he's stronger than the previous
_G global variable (which still exists, but it can be eliminated via _ENV). Also,
setfenv and
getfenv will dissapear. You manually set _ENV to whatever you want before creating a function. setfenv was sometimes used when loading and executing code from a file or string (for sandboxes). Since it's deprecated now, they created a function just for that, called loadIn.
The other important changes for me are:
- The bit lib
- ipairs is deprecated in the current version (which is ok, I guess, since the numeric for is equivalent and faster. In some rare occasions someone might need to implement their own ipairs though)
- unpack has been put inside table: table.unpack . There's also a table.pack function, not exactly inverse, but nearly.
- The debug lib is not loaded by default
- Empty statements (a semicolon) are allowed - useful for machine-generated code.
- Strings have a "ignore all the blank characters until the next non-black thing" escape char. This will be very useful for creating 2d maps in the code, while keeping proper indentation.
Most of the other changes are C-related, or not very interesting to me.
I would have thought that
module was being deprecated, but I could not find a reliable source confirming that. Nevertheless, everyone is running away from it nowadays.
Re: Lua 5.2, almost here
Posted: Thu Dec 08, 2011 12:18 pm
by miko
ishkabible wrote:so Lua 5.2 is almost here and it will hopefully "change the way the way you love" what are you looking forward too in 5.2? what do not like?
something i don't like: in Lua 5.2, the goto statement was added...bleh, why?!
The most important (in positive sense) change for me is the dissappearance of module(), and the way I create modules (returning a table value, not messing with globals), which is still compatible with 5.1.
Bit library is nice, but since I use love with luajit, I already have it. For me, there is no rush to upgrade to 5.2.
As of goto... I will never use it anyway. I still remember my first programs in Basic with lots of goto's.
Re: Lua 5.2, almost here
Posted: Thu Dec 08, 2011 1:34 pm
by vrld
ishkabible wrote:something i don't like: in Lua 5.2, the goto statement was added...bleh, why?!
Goto has at least the use case as break/continue statement (Luas
break only allows breaking out of the inner loop):
Code: Select all
while some_condition do
while some_other_condition do
if break_condition then
goto done
elseif inner_break_condition then
goto continue
end
end
::continue::
stuff()
end
::done::
more_code()
The Lua 5.1 equivalent is hackish and ugly in comparison:
Code: Select all
(function()
while some_condition do
if "break" == (function()
while some_other_condition do
if break_condition then
return "break"
elseif inner_break_condition then
return
end
end
end)() then return end
stuff()
end
end)()
more_code()
It could also be useful for cleanup after errors, as often used in the
Linux kernel:
Code: Select all
function foo()
if not one() then goto on_error
elseif not two() then goto cleanup_one
elseif not three() then goto cleanup_two
else return true end
::cleanup_two::
undo_two()
::cleanup_one::
undo_two()
::on_error::
return false
end
What I'm exited about:
- finalizers for tables
- tables honor the __len metamethod
Re: Lua 5.2, almost here
Posted: Thu Dec 08, 2011 2:48 pm
by slime
kikito wrote:
- ipairs is deprecated in the current version (which is ok, I guess, since the numeric for is equivalent and faster. In some rare occasions someone might need to implement their own ipairs though)
ipairs was un-deprecated/un-removed several months ago, I think.