lua-users home
lua-l archive

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

2014-03-30 19:57 GMT+02:00 Andrew Starks <>:

> Because `strict` is not part of the standard library, it is not as
> conveniently at hand. Therefore, people reinvent it or don't include
> it and, as a result, it's not part of the language's "culture."

True. But not necessarily bad.

I am currently working on a program I am revising to take
advantage of 5.3 (utf8 and no `=` needed). It contains:

local globals = {}
__index=function(tbl, key)
   local val=rawget(tbl,key)
   if val then return val end
   val = globals[key]
   if val then return val end
   if key:match("%u%l") then return guess(key)

The reason I mention this is because the trick is the same
one that strict.lua uses. I suppose this counts are reinventing
it, but I adapt it to a somewhat different purpose.

> That is, it can't become a "best practice" to enable it or include it and
> it can't be considered properly in modules that people may write. It's
> not a bug if they create globals, necessarily, and you can't expect
> someone else to `rawset(_ENV, x, 1)` when the do.

Which IMHO is a good thing.

> ##Proposal
> My idea (probably not a new one) is in two parts:
> 1: `global` keyword is (probably) shorthand for rawset(_ENV, var, val)

The effect of this proposal can be achieved easily. The syntax is only
slightly different: `global {var1=val1; var2=val2}` instead of
`global var1,var2=val1,val2`.

The Lua way is to provide methods, not policies. This proposal
involves policy, not method. I do not support it.