lua-users home
lua-l archive

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

On 13/01/17 12:00 PM, Soni L. wrote:

On 13/01/17 08:27 AM, Dibyendu Majumdar wrote:
On 13 January 2017 at 09:52, Daurnimator <> wrote:
On 13 January 2017 at 20:01, steve donovan <> wrote:
On Fri, Jan 13, 2017 at 9:43 AM, Dirk Laurie <> wrote:
Isn't it possible to mimic setfenv and getfenv (inefficiently) in
"pure" Lua 5.3 via the debug library?
Well, naturally but the documentation also warns that the debug
library can be very slow.

_ENV never freaked me out because I never use it ;)  And never missed
setfenv either.
_ENV can be a bit weird to get used to, but once you start using it
you start to come up with nice new patterns/idioms.

However the reason I don't use _ENV more often is I often have to end
up writing code with lua 5.1 compatibility.

In Ravi I would like to add support for 5.1 and 5.2 backward
compatibility. Has anyone implemented the missing features of 5.1 in
5.3 that I can look at?

I have no experience with 5.1 and do not know how setfenv/getfenv ad
related C api functions should be implemented, but I would like to add
these to Ravi.

Thanks and Regards

I did some thinking on it a while back, but I can't recall what I came up with...

I *think* I talked about it somewhere on my github[1], maybe on the SExLua repo[2], but yeah idk.

(Or maybe it was on this list, scattered across multiple threads...)

Just make every function have an _ENV, whether it uses globals or not. Then basically upvaluejoin when setfenv and return it when getfenv - don't bother with temporary in-function environments, since those are not *the* function's environment.


PS: I personally like the idea of having multiple compilers (one for 5.1, one for 5.2, one for 5.3) for the same VM, since there were library semantic changes between 5.1/5.2/5.3 and those aren't easy to autodetect while also supporting multiple lua versions. Then invoke their stdlib with require"5.1" and call .load(5.1 code) and the 5.1 code gets loaded 1. with the right stdlib 2. with the right operator/etc semantics

Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.