lua-users home
lua-l archive

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


We're considering moving to Lua 5.2 upon release. While it's looking promising, the biggest hurdle for us is the abolition of getfenv.

We're using getfenv to simulate Python's package system, such that:

import 'hello.world'

imports a lua file into the variable 'world' of _this_ environment.

One could imagine the implementation would look something like this:

function import(fname)
    ...
    local this_env = {}
    loadin(fname, this_env)
    local calling_env = getfenv(2)
    calling_env['world'] = this_env
end

Is this possible to emulate using Lua 5.2 without having to use:

world = import 'hello.world'

many thanks,
Tom