[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: 5.2 and 5.1
- From: Miles Bader <miles@...>
- Date: Wed, 10 Apr 2013 11:59:40 +0900
Joshua Jensen <email@example.com> writes:
>> On Tue, Apr 9, 2013 at 9:02 AM, Coda Highland <firstname.lastname@example.org
>> <mailto:email@example.com>> wrote:
>> You're going to be waiting a very long time, then. 5.2 isn't on
>> LuaJIT's roadmap at all.
>> But you can compile LuaJIT to have a lot of Lua 5.2 compatibility,
>> although without _ENV and overriding __gc for tables. I don't think
>> Mike P regards the latter as intrinsically bad, but he will wait for
>> his new garbage collector in 2.1 before implementing it.
Yeah, "5.2" is probably the wrong granularity to think about it.
LuaJIT has indeed added a bunch of features from 5.2, just not _all_
As not everybody needs every feature, it can be compatible for some
people even if it's not for everybody.
> Someone posted an _ENV patch for LuaJIT a while back:
> I've never tried it, but there you go.
One thing that might be neat is if LuaJIT (and maybe even any future
releases of Lua 5.1) just added the 5.2-style four-argument load
function (and loadfile).
I think for much code, that's all that's necessary to be 5.2
compatible -- explicit use of _ENV is not always necessary (e.g. my
code which used to use setfenv, doesn't use _ENV in 5.2, just load).
Since doing this is almost trivial, and results in more elegant and
readable code, I can't see why there'd be any objection ... :]
local old_load, old_loadfile = load, loadfile
function load (ld, source, mode, env)
-- dunno about mode, but
if type (ld) == 'string' then
fun = loadstring (ld)
fun = old_load (ld, source)
if env then
setfenv (fun, env)
-- loadfile etc
"Don't just question authority,
Don't forget to question me."
-- Jello Biafra