lua - Lazy Loading μ§μ° λ‘λ©
μ§μ° λ‘λ©(lazy loading)μ νμν λλ§ λ¦¬μμ€λ₯Ό λ‘λνλ κΈ°λ²μΌλ‘, μ΄κΈ° λ‘λ© μκ°μ μ€μ΄κ³ λ©λͺ¨λ¦¬ μ¬μ©μ μ΅μ ννλ λ° μ μ©νλ€. Luaμμ μ§μ° λ‘λ©μ ꡬννλ λ°©λ²μ λ€μκ³Ό κ°λ€. μ§μ° λ‘λ© κ΅¬ν λ°©λ² ν¨μλ‘ λͺ¨λ λ‘λ: λͺ¨λμ μ§μ λ‘λνλ λμ , νμν λ νΈμΆλλ ν¨μλ₯Ό μ μνμ¬ λͺ¨λμ λ‘λνλ€. λ³μλ‘ λͺ¨λ μ μ₯: λͺ¨λμ λ‘λν ν, κ·Έ κ²°κ³Όλ₯Ό λ³μμ μ μ₯νμ¬ μ΄νμ μ¬μ¬μ©ν μ μλλ‘ νλ€. μμ mymodule.lua (λͺ¨λ νμΌ) local M = {} function M.hello() print("Hello from mymodule!") end function M.goodbye() print("Goodbye from mymodule!") end return M main.lua (λ©μΈ νλ‘κ·Έλ¨) local mymodule -- λͺ¨λμ 미리 μ μΈνμ§λ§ λ‘λνμ§ μμ local function loadModule() if not mymodule then mymodule = require 'mymodule' -- νμν λ λͺ¨λ λ‘λ end end -- νΉμ 쑰건μ λ°λΌ λͺ¨λμ ν¨μλ₯Ό νΈμΆ local condition = true if condition then loadModule() -- λͺ¨λ λ‘λ mymodule.hello() -- λͺ¨λμ ν¨μ μ¬μ© else print("λͺ¨λμ λ‘λνμ§ μμμ΅λλ€.") end μ€λͺ λͺ¨λ νμΌ: mymodule.lua νμΌμλ λ κ°μ ν¨μ helloμ goodbyeκ° μ μλμ΄ μλ€. ...