From c27c23074c8e89aa31e294c60119e4453f76fbd5 Mon Sep 17 00:00:00 2001 From: mbartlett21 <29034492+mbartlett21@users.noreply.github.com> Date: Fri, 17 Jan 2020 12:08:54 +1000 Subject: [PATCH] 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 --- src/buffer.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index ac5c531..ae00ef2 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -114,10 +114,18 @@ int buffer_meth_receive(lua_State *L, p_buffer buf) { luaL_addlstring(&b, part, size); /* receive new patterns */ if (!lua_isnumber(L, 2)) { - const char *p= luaL_optstring(L, 2, "*l"); - if (p[0] == '*' && p[1] == 'l') err = recvline(buf, &b); - else if (p[0] == '*' && p[1] == 'a') err = recvall(buf, &b); - else luaL_argcheck(L, 0, 2, "invalid receive pattern"); + const char *p = luaL_optstring(L, 2, "l"); + if (*p == '*') p++; /* skip optional '*' (for compatibility) */ + switch (*p) { + 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 * received) */ } else {