包路径 |
|
whatever = require "whatever"
Lua 会尝试在许多地方找到名为 whatever
的包,这些地方大多在名称中包含 whatever
。如果找不到任何匹配项,Lua 会给出错误信息,列出所有尝试过的地方,例如
stdin:1: module 'whatever' not found: no field package.preload['whatever'] no file '/usr/local/share/lua/5.2/whatever.lua' no file '/usr/local/share/lua/5.2/whatever/init.lua' no file '/usr/local/lib/lua/5.2/whatever.lua' no file '/usr/local/lib/lua/5.2/whatever/init.lua' no file './whatever.lua' no file '/usr/local/lib/lua/5.2/whatever.so' no file '/usr/local/lib/lua/5.2/loadall.so' no file './whatever.so' stack traceback: [C]: in function 'require' stdin:1: in main chunk [C]: in ?
该列表的示意图保存在变量 package.path
中。对于上面的列表,该变量包含
/usr/local/share/lua/5.2/?.lua;/usr/local/share/lua/5.2/?/init.lua;/usr/local/lib/lua/5.2/?.lua;/usr/local/lib/lua/5.2/?/init.lua;./?.lua