Prevent defining environment-level globals in programs
SquidDev opened this issue ยท 3 comments
@Lupus590 recently added a strict mode to mbs's shell (SquidDev-CC/mbs@031d3c7), which raises an error when a program tries to define a global within its environment table.
It'd be nice to integrate something similar into the CraftOS shell. Most of the time defining globals is a bug in the program's code (due to someone missing a local
). That said, in the interest of backwards compatibility, it's probably worth leaving off for the time being.
I'm also not 100% happy with the error message in the attached PR (sorry Lupus :p), so suggestions are welcome!
settings: general.enable_globals
Warning: Global on line X of file Y
Show this after execution finishes.
Maybe include an API for telling the shell to ignore this behaviour
shell.ignoreGlobals()
Considering this would be just a option (that most sane people would turn on in instant) i would say having just "Attempt to create global " .. tostring(name)
as error would make it simple to scour the file to find it. Unless there is a way to get a line number too? No need for that extra info about _G in my opinion. Also to comment of preceding comment erroring with this optional setting on would make more sense then just writing a warning afterwards.