找不到模块插槽 [英] Module socket not found lua

查看:144
本文介绍了找不到模块插槽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用lua从nginx访问redis值.当我在命令行上执行lua文件时,一切正常,我能够读取和写入Redis值.但是我尝试通过访问在其中写入access_by_lua指令的位置从nginx执行相同的文件时,在错误日志文件中记录了以下错误

I am trying to use lua to access redis values from nginx. When i execute lua files on command line there everything is ok i am able to read and write values to redis. But i when try to execute the same files from nginx by accessing a location in which access_by_lua directive is written the following error logged in error log file

no field package.preload['socket'] 
no file '/home/sivag/redis/redis-lua/src/socket.lua'
no file 'src/socket.lua'
no file '/home/sivag/lua/socket.lua'
no file '/opt/openresty/lualib/socket.so'
no file './socket.so'
no file '/usr/local/lib/lua/5.1/socket.so'
no file '/opt/openresty/luajit/lib/lua/5.1/socket.so'
no file '/usr/local/lib/lua/5.1/loadall.so'

这是什么原因,我该如何解决?

What is the reason for this and how can i resolve this?

推荐答案

由于代码执行命令require("socket"),您会收到此错误 此命令将在几个目录中搜索具有该名称的文件.如果成功,内容将作为Lua代码执行.如果操作不成功,您将收到错误消息.

You get this error because your code executes the command require("socket") This command will search for a file with that name in several directories. If successful the content will be executed as Lua code. If it is not successful you'll end up with your error message.

要解决此问题,必须将包含文件的路径添加到系统变量 LUA_PATH ,或者必须将其添加到全局表package.path,因为需要文件. 卢阿会取代吗?加上您给require()赋予的名称

In order to fix this you have to add the path containing the file either to the system variable LUA_PATH or you have to add it to the global table package.path befor you require the file. Lua will replace ? with the name you give to require()

例如

package.path = package.path .. ";" .. thisPathContainsTheLuaFile .. "?.lua"

请阅读:

http://www.lua.org/manual/5.3/manual.html#pdf-需要

https://www.lua.org/pil/8.1.html

这篇关于找不到模块插槽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆