参考链接:
https://www.cnblogs.com/smallboat/p/5552407.html
https://blog.csdn.net/andy1515/article/details/105801021
https://blog.csdn.net/fightsyj/article/details/90314632?utm_medium=distribute.pc_relevant.none-task-blog-OPENSEARCH-1.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-OPENSEARCH-1.nonecase
1.package.path
打印一下加载路径,如下,其中框住的表示当前目录。当require时,会用参数去替换“?”
print(package.path)
2.package.loaded
a.lua
a = {} a.b = 1 return a
b.lua(放在当前目录的folder文件夹下)
b = 2
test.lua
function PrintInfo() for k,v in pairs(package.loaded) do print(k,v,type(k)) end print("----------------------------") end PrintInfo() require("a") require("folder\\b") PrintInfo()
输出如下,可以看到require后,参数作为key,return值作为value(如果不return例如上面的b.lua,则默认返回true),保存在package.loaded中