lua-users home
lua-l archive

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


On Mon, Apr 14, 2014 at 6:29 PM, Coroutines <coroutines@gmail.com> wrote:
Looks pretty thorough, good job!  The only thing I saw that might be
worth mentioning is some modules monkey-patch globals

I wish that there was a way to monkeypatch variables with monkeypatching scope limited.

E.g. a function that takes a string as an argument, and then patches more functions to that (right now the only way to add more string methods is to patch the global string metatable, or wrap string inside something else). Also for patching tables with limited scope (i.e. patching a table inside a function would affect the table only inside the function). Maybe we need a function like setmonkeypatches(variable, {}) (compare that to setmetatable).

I could use it for example here:
https://github.com/bungle/lua-resty-template/blob/master/README.md#template-helpers

(Adding methods to global string, and table types (not encouraged, though))

But I assume this only adds unneccessary cruft to the language, and probably also hard to debug situations (why does this variable have a function here, but not here?).