1

Platform: (where Lua and LuaSocket are ported) An embedded system using ARM 7 development board running 3rd party RTOS with TCP/IP stack.

What works:

  • Using Lua standard library such as "io" calls, print, assert, etc
  • sending UDP packets by using the udp = assert(socket.udp) method, assert(udp:send(something))

Problem: When executing an example smtp lua script:

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;
}
thejartender
  • 9,339
  • 6
  • 34
  • 51
user1325966
  • 33
  • 1
  • 5

1 Answers1

2

Well, since the error says that "try is nil", then my best guess is that the C lib is not correctly, or not completely, linked to your Lua. This could be the result of a faulty installation, a missing lib, or something of that sort.

kikito
  • 51,734
  • 32
  • 149
  • 189
  • Hi Kikito, Thanks for your help. I think I fixed the problem by statically linking my socket "core" library which I didn't do it properly before. Thank you! – user1325966 Apr 13 '12 at 00:31
  • In that case, could you please mark my answer as valid? Just click on the the "gray ✔ symbol" on the left of this answer, so it turns green. – kikito Apr 13 '12 at 08:56
  • This happened to me too. In fact, he is missing this lib https://github.com/hjelmeland/try-lua/blob/master/try.lua . – Luiz Felipe Aug 03 '15 at 20:49