• 文档

lua_package_path可以配置openresty的文件寻址路径。官网文档如下:

 # 设置纯 Lua 扩展库的搜寻路径(';;' 是默认路径):
lua_package_path '/foo/bar/?.lua;/blah/?.lua;;'; # 设置 C 编写的 Lua 扩展模块的搜寻路径(也可以用 ';;'):
lua_package_cpath '/bar/baz/?.so;/blah/blah/?.so;;';

然后require的字符串就会替换对应的问号?,一个文件就会去/foo/bar/下面寻找。

  • example

在代码中require "controller.test",会依次根据package.path匹配对应的lua文件。即替换掉对应的问号。(在lapis框架中,在框架的根目录中创建一个文件夹名字叫controllers,写一个文件test.lua,可以正常输出,改为controller,找不到对应的文件夹,打开日志,查看openresty的寻找方式)

首先输出package.path:

/usr/local/openresty/site/lualib/?.lua;/usr/local/openresty/site/lualib/?/init.lua;/usr/local/openresty/lualib/?.lua;/usr/local/openresty/lualib/?/init.lua;./?.lua;/usr/local/openresty/luajit/share/luajit-2.1.0-beta2/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/openresty/luajit/share/lua/5.1/?.lua;/usr/local/openresty/luajit/share/lua/5.1/?/init.lua

在log中查看:

	no field package.preload['controller.test']
no file '/usr/local/openresty/site/lualib/controller/test.lua'
no file '/usr/local/openresty/site/lualib/controller/test/init.lua'
no file '/usr/local/openresty/lualib/controller/test.lua'
no file '/usr/local/openresty/lualib/controller/test/init.lua'
no file './controller/test.lua'
no file '/usr/local/openresty/luajit/share/luajit-2.1.0-beta2/controller/test.lua'
no file '/usr/local/share/lua/5.1/controller/test.lua'
no file '/usr/local/share/lua/5.1/controller/test/init.lua'
no file '/usr/local/openresty/luajit/share/lua/5.1/controller/test.lua'
no file '/usr/local/openresty/luajit/share/lua/5.1/controller/test/init.lua'
no file '/usr/local/openresty/site/lualib/controller/test.so'
no file '/usr/local/openresty/lualib/controller/test.so'
no file './controller/test.so'
no file '/usr/local/lib/lua/5.1/controller/test.so'
no file '/usr/local/openresty/luajit/lib/lua/5.1/controller/test.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file '/usr/local/openresty/site/lualib/controller.so'
no file '/usr/local/openresty/lualib/controller.so'
no file './controller.so'
no file '/usr/local/lib/lua/5.1/controller.so'
no file '/usr/local/openresty/luajit/lib/lua/5.1/controller.so'
no file '/usr/local/lib/lua/5.1/loadall.so'

openresty根据package.path依次替换到寻找文件,全部寻找完毕还找不到就报错。

最新文章

  1. windows中LNK文件打开方式恢复(每日一修(1))
  2. hbase集群的启动,注意几个问题
  3. mysql,实现数据库检索结果添加自增的序号
  4. 没学过CSS等前端的我,也想美化一下自己的博客
  5. MongoDB 副本集的原理、搭建、应用
  6. ios - GCD简单小结
  7. java简单统计.java文件中的有效代码行,空行,注释行
  8. 与众不同 windows phone (44) - 8.0 位置和地图
  9. Java 日期往后推迟n天
  10. 解决数据库datatime数据在DataGridView里不显示秒的解决
  11. 学习kernel编程的建议
  12. C语言 cgi(3)
  13. linux的命令使用记录
  14. java 四则混合运算 计算器
  15. js中的递归总结
  16. AOP 还在配置吗改用打标签模式吧!
  17. [译]asp-net-core-mvc-ajax-form-requests-using-jquery-unobtrusive
  18. css利用padding百分比实现图片自适应高度
  19. 20165220 Java第五周学习总结
  20. 2015-10-20 sql2

热门文章

  1. ironic rescue standard rescue and unrescue process
  2. 【现代程序设计】homework-01
  3. 波动数列 神奇的dp
  4. Java 循环队列的实现
  5. ASP.NET——实现两个下拉框动态联动
  6. bzoj2957:楼房重建
  7. Linux wget 安装JDK失败
  8. bzoj4104 [Thu Summer Camp 2015]解密运算
  9. [LeetCode] Binary Tree Inorder Traversal 中序排序
  10. 用vs2008和vs2005创建win32 console application