Last active
June 27, 2020 07:08
-
-
Save foriequal0/cf0dcdcc5998a46ec28440a22370464c to your computer and use it in GitHub Desktop.
lua lazy require
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
local _require = require | |
require = function (name) | |
local function singleton() | |
local m = _require(name) | |
singleton = function () | |
return m | |
end | |
return m | |
end | |
local meta = {} | |
meta.__index = function(t, k) | |
local m = singleton() | |
meta.__index = m | |
return m[k] | |
end | |
meta.__call = function(...) | |
local m = singleton() | |
meta.__call = function() return m(...) end | |
return m(...) | |
end | |
return setmetatable({}, meta) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
require한 모듈의 프로퍼티에 접근하는 시점에서 require를 실행합니다.