Created
March 25, 2018 09:55
-
-
Save DarkWiiPlayer/6cc47c3f950f029bbf6277039e044e61 to your computer and use it in GitHub Desktop.
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 mod = {} | |
local meta = { | |
__call = function(tab, ...) | |
if not tab.func then | |
tab.func = tab.loader() | |
end | |
tab.func(...) | |
end | |
} | |
function mod.lazyfunc(loader) | |
return setmetatable({loader=loader}, meta) | |
end | |
return mod |
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
print "I have been required" | |
return function(str) | |
print(("%s says hello ♥"):format(str)) | |
end |
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
import lazyfunc from require "lazy" | |
func = lazyfunc -> require "some_func" | |
print "Lazy loading function created" | |
func("moonscript") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment