lua-users home
lua-l archive

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


In udp.c of luasocket-2.0-alpha distribution, the function:

static int meth_setsockname(lua_State *L)
{
    /*v.a* bug: "udp{master}" is not a registered class of "udp" module
      so aux_checkclass fails as expected. Fix is to change this string
      to "udp{unconnected}".
    */
    p_udp udp = (p_udp) aux_checkclass(L, "udp{unconnected}", 1); /* <--- */
    const char *address =  luaL_checkstring(L, 2);
    unsigned short port = (unsigned short) luaL_checknumber(L, 3);
    const char *err = inet_trybind(&udp->sock, address, port, -1);
    if (err) {
        lua_pushnil(L);
        lua_pushstring(L, err);
        return 2;
    }
    lua_pushnumber(L, 1);
    return 1;
}

has a bug. Or at least it does not work. Also the documentation for
"setsockname" says that the function returns "nil" on success and
an error message on failure. The code in this function does not
reflect that. Consequently the "echosrvr.lua" example fails.
I fixed it simply by ignoring the first return value as in .
<code>
	<snip/>
	_, err = udp:setsockname(host, port) --> added "_, " to make it work.
	if err then print(err) os.exit() end
	<snip/>
</code>

I know the author has mentioned that the documentation will be updated.
I am curious in this instance which will be fixed, the documentation or
the code.

Finally, let me know if this is not the forum to post messages of this
nature.

-- v.a