Created
August 6, 2013 14:44
-
-
Save EndangeredMassa/6165122 to your computer and use it in GitHub Desktop.
Lua Requires
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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