|
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-Riofunction assign(key,value) rawset(_G,key,value) end setmetatable(_ENV,{__newindex =function() error"Global LHS values are banned." end})x=1stdin:2: Global LHS values are banned. stack traceback: [C]: in function 'error' stdin:2: in function '__newindex' stdin:1: in main chunk [C]: in ?=xnilassign('x',1) =x1
-- Thomas