Skip to content

Instantly share code, notes, and snippets.

@foriequal0
Last active June 27, 2020 07:08
Show Gist options
  • Save foriequal0/cf0dcdcc5998a46ec28440a22370464c to your computer and use it in GitHub Desktop.
Save foriequal0/cf0dcdcc5998a46ec28440a22370464c to your computer and use it in GitHub Desktop.
lua lazy require
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
@foriequal0
Copy link
Author

require한 모듈의 프로퍼티에 접근하는 시점에서 require를 실행합니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment