1 回答
TA贡献1860条经验 获得超8个赞
你运行lua时,test1.lua和test2.lua是在当前目录下吗?
Plain Text code
?
/tmp/ cat test1.lua
package.path = package.path .. ;./?.lua
local test2 = require(test2)
/tmp/ ~/tmp/lua-5.2.2/src/lua test1.lua 没问题
/tmp/ rm test2.lua 删掉test2.lua
/tmp/ ~/tmp/lua-5.2.2/src/lua test1.lua 报错了
/home/user/tmp/lua-5.2.2/src/lua: test1.lua:2: module ;test2; not found:
no field package.preload[;test2;]
no file ;/usr/local/share/lua/5.2/test2.lua;
no file ;/usr/local/share/lua/5.2/test2/init.lua;
no file ;/usr/local/lib/lua/5.2/test2.lua;
no file ;/usr/local/lib/lua/5.2/test2/init.lua;
no file ;./test2.lua;
no file ;./test2.lua;
no file ;/usr/local/lib/lua/5.2/test2.so;
no file ;/usr/local/lib/lua/5.2/loadall.so;
no file ;./test2.so;
stack traceback:
[C]: in function ;require;
test1.lua:2: in main chunk
[C]: in ?
/tmp/ touch test2.lua 重新建立test2.lua
/tmp/ ~/tmp/lua-5.2.2/src/lua test1.lua 没问题
/tmp/ cd ~/tmp 换到别的目录
~/tmp/ ~/tmp/lua-5.2.2/src/lua /tmp/test1.lua 出错了
/home/user/tmp/lua-5.2.2/src/lua: /tmp/test1.lua:2: module ;test2; not found:
no field package.preload[;test2;]
no file ;/usr/local/share/lua/5.2/test2.lua;
no file ;/usr/local/share/lua/5.2/test2/init.lua;
no file ;/usr/local/lib/lua/5.2/test2.lua;
no file ;/usr/local/lib/lua/5.2/test2/init.lua;
no file ;./test2.lua;
no file ;./test2.lua;
no file ;/usr/local/lib/lua/5.2/test2.so;
no file ;/usr/local/lib/lua/5.2/loadall.so;
no file ;./test2.so;
stack traceback:
[C]: in function ;require;
/tmp/test1.lua:2: in main chunk
[C]: in ?
添加回答
举报