TCP Receive without *

The TCP Receive code now uses a switch statement and allows dropping the * at the start of the string, like Lua's io library
This commit is contained in:
mbartlett21 2020-01-17 12:08:54 +10:00 committed by GitHub
parent 733af884f1
commit c27c23074c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -114,10 +114,18 @@ int buffer_meth_receive(lua_State *L, p_buffer buf) {
luaL_addlstring(&b, part, size); luaL_addlstring(&b, part, size);
/* receive new patterns */ /* receive new patterns */
if (!lua_isnumber(L, 2)) { if (!lua_isnumber(L, 2)) {
const char *p= luaL_optstring(L, 2, "*l"); const char *p = luaL_optstring(L, 2, "l");
if (p[0] == '*' && p[1] == 'l') err = recvline(buf, &b); if (*p == '*') p++; /* skip optional '*' (for compatibility) */
else if (p[0] == '*' && p[1] == 'a') err = recvall(buf, &b); switch (*p) {
else luaL_argcheck(L, 0, 2, "invalid receive pattern"); case 'l': /* line */
err = recvline(buf, &b);
break;
case 'a': /* all */
err = recvall(buf, &b);
break;
default:
luaL_argcheck(L, 0, 2, "invalid receive pattern");
}
/* get a fixed number of bytes (minus what was already partially /* get a fixed number of bytes (minus what was already partially
* received) */ * received) */
} else { } else {