Skip to content

Instantly share code, notes, and snippets.

@perusio
Last active December 26, 2015 02:39
Show Gist options
  • Save perusio/7080496 to your computer and use it in GitHub Desktop.
Save perusio/7080496 to your computer and use it in GitHub Desktop.
Limit access to the global environment in a Lua module to avoid side effects.
-- Include this after all import of global functions
-- and modules in your module.
-- If we are in Lua 5.1 this function exists.
if _G.setfenv then
setfenv(1, {})
else -- Lua 5.2.
_ENV = nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment