lua-users home
lua-l archive

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




On Sunday, March 30, 2014, Philipp Janda <siffiejoe@gmx.net> wrote:
Am 30.03.2014 19:57 schröbte Andrew Starks:

I think it's bad, because it might be motivation to not use strict or
to consider it a "hack."

It *is* a hack. An impressive one because it achieves a lot with little code, but on the other hand it modifies a shared resource, so it affects other people's code, and prevents them from setting a metatable on `_G` themselves (or at least makes it harder). And as you already mentioned, there are a lot of alternatives (most of which I consider superior to `strict.lua`), and this is my main motivation not to use `strict.lua` ...


##Proposal

My idea (probably not a new one) is in two parts:

1: `global` keyword is (probably) shorthand for rawset(_ENV, var, val)

Most module writers would probably use `rawset` directly anyway, because it is compatible with Lua 5.x (for x < 3). I think the current approach is `var = nil` somewhere at top level, which is also backwards compatible. So, IMHO, a new keyword would do more harm than good ...


If 5.3 has new keywords, then global is just one more parser issue to trap, so it's not a big deal to trap this one too.  

2: _STRICT is a value that is global and defaults to `false` (or nil,
but one must be able to assign it globally).

Why not just preload `strict.lua` instead?! 

I can do that. My point is that a natural method would make it more pervasive and less likely to be imemented in conflicting ways. 

Then people can `require` it if they want to. But I'd rather use something that works offline (at compile time), or at least can be enabled/disabled on a per-chunk basis (maybe as a fallback to the offline tool).

 I think that my suggestion achieves that with _STRICT

I might be missing something, though. 

Thanks!

-Andrew


Philipp