当我使用以下脚本时: local smtp = require("socket.smtp")local from = "from@host"local rcpt = "rcpt@host"local msg = { headers = { to = rcpt, subject = "Hi" }, body = "Hello"}smtp.send{from = from,rcpt = rcpt,source = smtp.message(
local smtp = require("socket.smtp") local from = "from@host" local rcpt = "rcpt@host" local msg = { headers = { to = rcpt, subject = "Hi" }, body = "Hello" } smtp.send{from = from,rcpt = rcpt,source = smtp.message(msg)}
我收到一条错误消息:lua entry thread aborted:runtime error:尝试跨越C-call边界.
我正在使用从Luaocks安装的最新luasocket和使用LuaJIT 2.1编译的nginx的Lua 5.1.是什么导致此错误消息,我该如何解决?
smtp.send使用LuaSocket的socket.protect函数来处理内部错误.此函数在C中实现,并且不允许在当前版本中产生(git HEAD中的版本现在允许在Lua 5.2上产生,请参阅讨论 here).显然有人试图从内部屈服.在LuaSocket包中的etc / dispatch.lua中(更好地使用git HEAD版本),有一个 replacement function forsocket.protect
应该允许在所有Lua版本上产生(以额外的临时协程为代价).您可以尝试使用该Lua函数替换C函数,如下所示:
local socket = require("socket") local base = _G -- paste modified socket.protect function here -- continue with your own code: local smtp = require("socket.smtp") -- ...