Skip to content

Instantly share code, notes, and snippets.

@DarkWiiPlayer
Created March 25, 2018 09:55
Show Gist options
  • Save DarkWiiPlayer/6cc47c3f950f029bbf6277039e044e61 to your computer and use it in GitHub Desktop.
Save DarkWiiPlayer/6cc47c3f950f029bbf6277039e044e61 to your computer and use it in GitHub Desktop.
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
print "I have been required"
return function(str)
print(("%s says hello ♥"):format(str))
end
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