You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently luacheck marks the function thatUsesTable as setting non-standard global variable. However due to the setfenv call above it thatUsesTable is set on the table modulename/M.
I know setfenv/getfenv have been moved to debug in later versions of Lua, but it would be nice to have Luacheck recognise that all code after a setfenv is non-global unless the second parameter is the global table.
The text was updated successfully, but these errors were encountered:
This would be convenient, but it's not easy to detect all setfenv calls (e.g. they may be wrapped in some auxiliary function like the old module()), and more importantly, the best practice is to use local table instead of setfenv or module (http://kiki.to/blog/2014/03/31/rule-2-return-a-local-table/).
There is already some support for modules using globals, try putting -- luacheck: allow defined, module after the setfenv call.
Thanks for the link and the inline instruction, both very useful.
A brute force approach might be to evaluate getfenv(0)==getfenv(1) after each function call. I'm assuming that only setfenv changes the environment in 5.1. I know there's the new _ENV variable in 5.2.
In Lua 5.1 I am in the habit of writing Lua files in the from:
Taken from Programming in Lua 15.4 .
Currently luacheck marks the function thatUsesTable as setting non-standard global variable. However due to the setfenv call above it
thatUsesTable
is set on the tablemodulename
/M
.I know setfenv/getfenv have been moved to debug in later versions of Lua, but it would be nice to have Luacheck recognise that all code after a setfenv is non-global unless the second parameter is the global table.
The text was updated successfully, but these errors were encountered: