lua-users home
lua-l archive

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


On 23 October 2011 15:36, Sam Roberts <vieuxtech@gmail.com> wrote:
>

> I actually started using a lint tool for python, because it doesn't
> have a way to make libs like logging globally available across an
> entire app, you have to import it everywhere you use it. (actually, it
> probably does have a way to do this, but would involve doing things to
> the core that would be frowned upon by pythonistas everywhere)
>
> I got tired of integration tests failing because I'd put calls to
> logging.debug() in some code, and forget to add the import, so for the
> first time ever with a dynamic language, I found a lint tool and
> started using it. I feel its a failing in python that I'd not like lua
> to repeat. And its sucked valuable time from me, our integration tests
> take a long time to run and get back to us with a "you forgot to
> import logging, try again" message.
>

I've done this before:

    setmetatable(_ENV or _G, {
        __index = function (env, modulename)
                local ok, module = pcall(require, modulename);
                if ok then
                        rawset(env, modulename, module);
                        return module;
                end
        end;
    })

I consider it a little hacky, but that's largely subjective (similar
to module() setting globals, but at least the end developer has a
choice here).

Regards,
Matthew