lua-users home
lua-l archive

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


Am 16.04.2013 04:36 schröbte Miles Bader:
Philipp Janda <siffiejoe@gmx.net> writes:
   if _VERSION == "Lua 5.1" then
     setfenv( f, env )
   end

BTW, it seems much cleaner to just do:

    if setfenv then setfenv (f, env) end

Yes, but (related to another thread) I do

local setfenv = setfenv
if _VERSION == "Lua 5.1" then
  assert( setfenv )
end

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.

  [1]: https://github.com/davidm/lua-compat-env
[2]: https://github.com/stevedonovan/Penlight/blob/master/lua/pl/utils.lua
  [3]: http://lua-users.org/lists/lua-l/2010-06/msg00313.html


-miles


Philipp