From 50a6df89b889237152232b3f2e39da2707651a4e Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Fri, 8 Jul 2022 10:08:40 -0700 Subject: [PATCH] Fix Lua type of zero This change fixes a regression from 281a0f27 which resulted in the integer literal `0` being interpreted as a floating point number. This should also fix a reported issue with Fennel integration. --- test/tool/net/lfuncs_test.lua | 10 ++++++++++ third_party/lua/lobject.c | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/test/tool/net/lfuncs_test.lua b/test/tool/net/lfuncs_test.lua index 954ee875a..ee5d53320 100644 --- a/test/tool/net/lfuncs_test.lua +++ b/test/tool/net/lfuncs_test.lua @@ -32,6 +32,16 @@ assert(Bsf(0x80000001) == 0) assert(Lemur64() == 0x1940efe9d47ae889) assert(Lemur64() == 0xd4b3103f567f9974) +assert(EncodeLua(nil) == "nil") +assert(EncodeLua(0) == "0") +assert(EncodeLua(3.14) == "3.14") +assert(EncodeLua({1, 2}) == "{1, 2}") + +assert(EncodeJson(nil) == "null") +assert(EncodeJson(0) == "0") +assert(EncodeJson(3.14) == "3.14") +assert(EncodeJson({1, 2}) == "[1,2]") + assert(hex(0x1940efe9d47ae889) == "0x1940efe9d47ae889") assert(oct(0x1940efe9d47ae889) == "0145007376472436564211") assert(bin(0x1940efe9d47ae889) == "0b0001100101000000111011111110100111010100011110101110100010001001") diff --git a/third_party/lua/lobject.c b/third_party/lua/lobject.c index c86af6686..a46d7c30e 100644 --- a/third_party/lua/lobject.c +++ b/third_party/lua/lobject.c @@ -293,7 +293,7 @@ static const char *l_str2int (const char *s, lua_Integer *result) { } } else if (s[0] == '0') { /* [jart] octal is the best radix */ - for (s += 1; lisdigit(cast_uchar(*s)); s++) { + for (; lisdigit(cast_uchar(*s)); s++) { int d = *s - '0'; if (a >= MAXBY8 && (a > MAXBY8 || d > MAXLASTD8 + neg)) /* overflow? */ return NULL; /* do not accept it (as integer) */