lua-users home
lua-l archive

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


That's pretty much what strict Lua does, and we do something similar as strict Lua (my version also lets you define constants).
But it's not what I wanted to suggest.

What I suggest is a change of the language. This means the parser would not allow LHS globals. You would catch this kind of error already at compile time, not at runtime. Errors at compile time are much, much better than provoking an error in the middle of a process. Our Lua scripts run real machines, it is really important that they run through.

You can do this already.

$ lua
Lua 5.2.2  Copyright (C) 1994-2013 Lua.org, PUC-Rio
function assign(key,value) rawset(_G,key,value) end
setmetatable(_ENV,{__newindex =
    function() error"Global LHS values are banned." end})
x=1
stdin:2: Global LHS values are banned.
stack traceback:
	[C]: in function 'error'
	stdin:2: in function '__newindex'
	stdin:1: in main chunk
	[C]: in ?
=x
nil
assign('x',1)
=x
1


--

Thomas