Search code examples
lua

How to deal with Lua warning setting non-standard global variable?


When I tried to declare a global variable luachecks always showing the warning setting non-standard global variable .I wonder how can I fix this.(Not just ignore the warning,but setting a global variable in a standard way)


Solution

  • The warning isn't that you're setting a global variable in a non-standard way. It's that you're setting one at all. Once your user code starts running, all of the standard global variables are already done being set. You should use local variables instead as much as you can. If you really need to set your own global variables anyway, then pass their names with --globals to luacheck to ignore the warning for them.