[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: 5.2 and 5.1
- From: Miles Bader <miles@...>
- Date: Wed, 10 Apr 2013 11:59:40 +0900
Joshua Jensen <josh.jjensen@gmail.com> writes:
>> On Tue, Apr 9, 2013 at 9:02 AM, Coda Highland <chighland@gmail.com
>> <mailto:chighland@gmail.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_
of them.
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:
>
> http://permalink.gmane.org/gmane.comp.lang.lua.luajit/1392
>
> 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
local fun
if type (ld) == 'string' then
fun = loadstring (ld)
else
fun = old_load (ld, source)
end
if env then
setfenv (fun, env)
end
return fun
end
-- loadfile etc
-miles
--
"Don't just question authority,
Don't forget to question me."
-- Jello Biafra