lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 6 April 2013 17:35, Laurent Faillie <l_faillie@yahoo.com> wrote:
> Hello,
>
> I have the following code :
>
>        local socket = require("socket")
>        local clt = socket.try(socket.connect( "celeron.chez.moi", 7634 ))
>        local try = socket.newtry(function() clt:close() end)
>        local s, err = clt:receive('*a')
>        clt:close()
>
> And I'm testing it with Lua 5.1.5
>
> It tried it on 2 machines with "similar" configuration.
> On the first machine, is it working, but on a second one, I got a
>     /usr/bin/lua: (error object is not a string)
>
> As per http://www.luafaq.org/, it's due to 'error' handling.
> Any idea how I can trouble shoot ?

socket.try() throws a table as an error, not a string (i.e. not an
error message). It's designed to be used with socket.protect().

These functions are primarily used inside LuaSocket itself. If you
want to throw a normal error when the connection fails, use assert():

        local socket = require("socket")
        local clt = assert(socket.connect( "celeron.chez.moi", 7634 ))
        local s, err = clt:receive('*a')
        clt:close()

If you are definitely sure you want to use socket.try() instead, read
the documentation on socket.newtry() and socket.protect() as well.

Regards,
Matthew