天天看點

lua require

1.lua require傳回對象

mu.lua

mu={}

mu.constant = "這是一個常量"

function mu.func1()
        io.write("這是一個公有函數!\n")
end

return mu
           

test_mu.lua

require("mu")

print(mu.constant)

mu.func1()
           

測試指令:lua test_mu.lua

測試結果:

這是一個常量

這是一個公有函數!

2.lua require傳回函數

local function calcWeight(w)
        print(w*9.8)
end

return calcWeight
           
require("mg")(100)
           

繼續閱讀