Skip to content

Instantly share code, notes, and snippets.

@EndangeredMassa
Created August 6, 2013 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EndangeredMassa/6165122 to your computer and use it in GitHub Desktop.
Save EndangeredMassa/6165122 to your computer and use it in GitHub Desktop.
Lua Requires
-- GLOBAL CHANGES --
-- make requires return the object --
_require = _G.require
_G.require = function (name)
local original = _G[name]
_require(name)
local package = _G[name]
_G[name] = original
return package
end
-- creating contexts for files --
_G.declareContext = function ()
_G.declarePackageContext(nil)
end
_G.declarePackageContext = function (packageName)
local exports = {};
setmetatable(exports, {__index = _G})
if (packageName) then
_G[packageName] = exports;
end
setfenv(2, exports)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment