lua-users home
lua-l archive

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


I just found a way to get it to work:

    sock = socket.tcp(cv)

    function propersrc()
    if done then return nil end
    local chunk, err, partial = sock:receive(socket.BLOCKSIZE)
    if not err then return chunk
    elseif err == "closed" then
    sock:close()
    done = 1
    return partial
    else return nil, err end
    end
   

    for _, v in mp.unpacker(propersrc) do
        print("UNPACK: ",v)
    end

(basically by copying some code from https://github.com/diegonehab/luasocket/blob/d80bb0d82ba105c8fdb27e6174c267965d06ffb0/src/socket.lua obviously this is not the right way though,
so I'd be interested in knowing how you're supposed to do it)

cheers

Chris

On Mon, Oct 13, 2014 at 5:29 PM, chris 0 <viscousplacebo@gmail.com> wrote:
Hi,

I'm trying to use luasockets + msgpack together,
as it looks like msgpack supports ltn12, but I just can't
seem to get it to work:

    sock = socket.tcp(cv)
    src = "">
    for _, v in mp.unpacker(src) do
        print(v)
    end


Results in:
 bad argument #1 to unpacker (string or function expected, got table)

Whereas the following works:

local ltn12 = require 'ltn12'
src = "" 'r'))
for _, v in mp.unpacker(src) do
    print(v)
end

Is there something wrong with the source that the socket is producing, as it seems to
be a table?

cheers

Chris