lua-users home
lua-l archive

Lua 5.2 - emulation of old setfenv

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


Hi All!
I recently began playing a bit with Lua 5.2.0 (alpha). I downloaded and compiled the source (WinXp + TDM mingw 4.5.1) - no problem here. My problem is that I have some script I made for 5.4.1 which make heavy use of setfenv/getenv that don't work in 5.2. I know about _ENV and the 5.2 new approach to environments, but I didn't follow the fine print in the past threads about setfenv becoming deprecated, so I had some difficulty wading through old posts, so here is my problem: Is there a _pure Lua approach_ (some debug library trick) do rewrite sefenv/getenv? I tried reading/writing the first upvalue of a function using debug.set/getupvalue, but It didn't work in my use case. In doing this I assumed that _ENV is always the first upvalue of a function. Reading 5.2 docs it seems true, but I remember some old post in which Roberto (or maybe Luiz?) said it isn't always like that (but maybe I remember something superseded by newer work versions).
Any help appreciated!
Thanks in advance.
--
Lorenzo

AltStyle によって変換されたページ (->オリジナル) /