lua entry thread aborted: runtime error: attempt to call a string value

147 views
Skip to first unread message

朱茂海

unread,
Oct 12, 2012, 9:03:51 AM10/12/12
to open...@googlegroups.com
 local func = function (m)
           return "\"http://"..string.reverse(m[1])
  end
body1,_=ngx.re.gsub(body1,"['\"]http://(.*?)([/'\"])",func)

出现lua entry thread aborted: runtime error: attempt to call a string value错误,是什么原因呢。

Lance

unread,
Oct 12, 2012, 12:36:14 PM10/12/12
to open...@googlegroups.com

agentzh

unread,
Oct 12, 2012, 2:55:45 PM10/12/12
to open...@googlegroups.com
Hello!

在 Linux x86_64 上使用 nginx 1.2.4 + ngx_lua 0.7.0
运行你的示例代码无法复现你这里的错误。由于你的示例代码是不完整的,比如我不知道 body1 的初始值,也不知道你使用的是
access_by_lua, rewrite_by_lua,还是 content_by_lua,所以我自己随便假想了一下你的用法。我的
nginx.conf 片段是

location = /lua {
content_by_lua_file html/a.lua;
}

而 html/a.lua 的内容是:

local body1 = "'http://agentzh.org'"


local func = function (m)
return "\"http://"..string.reverse(m[1])
end
body1,_=ngx.re.gsub(body1,"['\"]http://(.*?)([/'\"])",func)

ngx.say(body1)

agentzh

unread,
Oct 12, 2012, 3:01:43 PM10/12/12
to open...@googlegroups.com
Hello!

刚才我回的邮件没写完就不小心发送出去了,不好意思。下面接着写:

On Fri, Oct 12, 2012 at 11:55 AM, agentzh wrote:
> 我的 nginx.conf 片段是
>
> location = /lua {
> content_by_lua_file html/a.lua;
> }
>
> 而 html/a.lua 的内容是:
>
> local body1 = "'http://agentzh.org'"
> local func = function (m)
> return "\"http://"..string.reverse(m[1])
> end
> body1,_=ngx.re.gsub(body1,"['\"]http://(.*?)([/'\"])",func)
> ngx.say(body1)

然后请求这里定义 /lua 的结果在我这里是期望的:

"http://gro.hztnega

所以请你也能提供像我上面给出的这样比较完整的示例,这样我才有可能在我这里复现你遇到的问题,否则就只能靠猜测了(像上面那样) :)

同时也希望你能在 bug 报告中总是主动提供像软件版本号(在这里就是 ngx_lua 和 nginx 的版本)、操作系统的种类(包括是 32
位的还是 64 位的)等重要信息。

多谢!
-agentzh

Message has been deleted

朱茂海

unread,
Oct 12, 2012, 8:57:33 PM10/12/12
to open...@googlegroups.com
不好意思,没提供详细的描述。
环境:nginx-1.2.3 ngx_lua 0.7 luajit-2.0  centos-5.8 32位



content_by_lua_file "/usr/local/nginx/conf/lua"

lua代码:

local func = function (m)
       return "\"http://"..string.reverse(m[1])..m[2]
end
body1,_=ngx.re.gsub(body1,"['\"]http://(.*?)([/'\"])",func)



body1的内容为百度首页源代码。

agentzh

unread,
Oct 12, 2012, 10:43:34 PM10/12/12
to open...@googlegroups.com
Hello!

2012/10/12 朱茂海:


> 不好意思,没提供详细的描述。
> 环境:nginx-1.2.3 ngx_lua 0.7 luajit-2.0 centos-5.8 32位
> content_by_lua_file "/usr/local/nginx/conf/lua"
>
> lua代码:
>
> local func = function (m)
> return "\"http://"..string.reverse(m[1])..m[2]
> end
> body1,_=ngx.re.gsub(body1,"['\"]http://(.*?)([/'\"])",func)
>
> body1的内容为百度首页源代码。
>

多谢你提供的用例!我已经成功在我本地复现了此错误并且提交了一个补丁修正了此问题:

https://github.com/chaoslawful/lua-nginx-module/commit/3875a33

你能否再在你那里尝试一下 ngx_lua 0.7.1rc1 这个版本?

https://github.com/chaoslawful/lua-nginx-module/tags/

多谢!

Best regards,
-agentzh

朱茂海

unread,
Oct 12, 2012, 11:55:51 PM10/12/12
to open...@googlegroups.com
非常感谢,问题已经解决!
Reply all
Reply to author
Forward
0 new messages