lua-users home
lua-l archive

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


On Wed, Apr 10, 2013 at 9:03 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> However, using it for namespacing ties one to 5.2 prematurely.
How about giving us a little example?

-- new style Lua 5.2 module
local _ENV = {}
function answer() return 42 end
return _ENV

By replacing the {} with a suitable function which does some setfenv magic on 5.1 we can get it to fly both ways, I will grant you. _ENV then has no special significance.

If that function then modified packaged.loaded then we could do without the dangling return _ENV on 5.2 as well.

But why not just

local M = {}
function M.answer() return 42 end
return M

?