LuaSocket - 尝试调用字段'try'(零值)

时间:2012-04-11 16:33:24

标签: lua luasocket

平台:(移植Lua和LuaSocket的地方) 使用ARM 7开发板的嵌入式系统,运行带有TCP / IP堆栈的第三方RTOS。

什么有效:

  • 使用Lua标准库,如“io”调用,打印,断言等
  • 使用udp = assert(socket.udp)方法发送UDP数据包,断言(udp:send(something))

问题: 执行示例smtp lua脚本时:

local smtp = require("socket.smtp")
from = "myEmail"
rcpt = {"<someOne's Email>"}
mesgt = { heasers = {someHeader}, body = "Hello World" } 
r, e = smtp.send {
    from = from,
    rcpt = rcpt, 
    source = smtp.message(mesgt),
    server = "someServer",
    port = 25,
}

-- an error returns after execution: 
-- lua\socket\smtp.lua:115: attempt to call field 'try' (a nil value)

-- Corresponding code in smtp.lua around line 115:

function open(server, port, create)
    local tp = socket.try(tp.connect(server or SERVER, port or PORT,
        TIMEOUT, create))
    local s = base.setmetatable({tp = tp}, metat)
    -- make sure tp is closed if we get an exception
    s.try = socket.newtry(function()
        s:close()
    end)
    return s
end

// Where try = newtry() in socket.lua and the corresponding C code is the same
// from the one provided with the library for UNIX:
static int global_newtry(lua_State *L) {
    lua_settop(L, 1);
    if (lua_isnil(L, 1)) lua_pushcfunction(L, do_nothing);
    lua_pushcclosure(L, finalize, 1);
    return 1;
}

1 个答案:

答案 0 :(得分:2)

好吧,因为错误说“try is nil”,那么我最好的猜测是C lib与你的Lua没有正确或不完全相关。这可能是安装错误,缺少lib或类似的结果。

相关问题