lua-users home
lua-l archive

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


Am 16.04.2013 16:35 schröbte Hisham:
On 16 April 2013 08:59, Philipp Janda <siffiejoe@gmx.net> wrote:
at the top of the file anyway, and some people have written setfenv[1][2][3]
for Lua 5.2 and I feared that one of those functions could end up in the
global environment, or -- even worse -- that someone wrote a completely
unrelated function with that name, since the name setfenv is fair game now
in Lua 5.2.

It's no more fair game now than it was before: nothing stops anyone
from redefining any globals. (They're not protected like keywords, of
course.)

If someone redefines a well-known and documented standard Lua function in an incompatible way, then it's not my fault in case something breaks. If, on the other hand, I use a magic name that isn't even mentioned in the current Lua reference manual anymore (except for the "Changes in ..." section), then it *is* my fault, IMHO. I think you should not be required to read/know the reference manuals of previous Lua versions to write working code, unless you explicitly want to support those previous versions, of course ...


That's why what I always wanted from the module system, instead of the
wild-west of package.seeall, was a way to get a guaranteed "reset"
environment (like a 'package.seebase' of sorts) with only the standard
Lua globals. If Lua can construct a default environment for the main
chunk and populate the standard libraries there, I figure it could
just as well do the same for modules, to ensure that module authors
can work with a stable set of assumptions about the environment, just
like script writers do.

I hear you, and I also like to make sure that my interface to Lua's standard library is sane, that's why I do those 'local setfenv = assert( setfenv )' assignments (checking for existence and maybe function type is all you can do in Lua). But sometimes it makes sense to remove certain parts of the standard library or replace them with different versions. E.g. there is no point in having a print function that writes to stdout if you don't have a console ...


-- Hisham
http://hisham.hm/


Philipp