lua-users home
lua-l archive

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




On 24/06/15 02:52 PM, Tim Hill wrote:
On Jun 23, 2015, at 4:46 PM, Daurnimator <quae@daurnimator.com> wrote:

As I replied on IRC; I think that lexically scoped metatables for the
base types are a much better idea.
I even coded up a proof of concept:
https://gist.github.com/daurnimator/dedd793e6f9b1f8d6b0c
(obviously if such a feature made it into PUC-lua, the `debug` calls
would be unnessecary)

I’m scratching my head on the utility of something like this.

Besides, if you want it, then the existing _ENV mechanism can do this for you. Just wrap the type in a metatable (a trivial bit of C code) and have it’s metamethods defer to functions in the current environment.

This is really the beauty of Lua; it’s meta-language model that provides the facilities whereby YOU can easily add these features without having to encumber the base language.

—Tim



You can't get enclosing closures.

function f()
-- _ENV = _ENV -- redundant because we're making g a global, so we need _ENV
  function g() (""):doSomething() end -- function has no _ENV
end
-- good luck getting the env of g :P

--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.