diff options
author | daurnimator <quae@daurnimator.com> | 2018-07-08 20:27:02 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2018-07-08 20:27:02 +1000 |
commit | 5b7f74d3cb2260b110bcd3308f782f65b4d9565f (patch) | |
tree | 4f4e46c7a9934757738bca7b85d34e0796f2d1f7 /vendor | |
parent | c72a963097b994d5dcaf3197ba45896a2a637885 (diff) | |
parent | 942e9fb5c80368fe93ca195bc14272b2d4cd2881 (diff) | |
download | luaossl-5b7f74d3cb2260b110bcd3308f782f65b4d9565f.tar.gz luaossl-5b7f74d3cb2260b110bcd3308f782f65b4d9565f.tar.bz2 luaossl-5b7f74d3cb2260b110bcd3308f782f65b4d9565f.zip |
Merge lua-compat-5.3 v0.7
Diffstat (limited to 'vendor')
-rw-r--r-- | vendor/compat53/c-api/compat-5.3.c | 29 | ||||
-rw-r--r-- | vendor/compat53/c-api/compat-5.3.h | 6 | ||||
-rwxr-xr-x | vendor/compat53/tests/test.lua | 5 | ||||
-rw-r--r-- | vendor/compat53/tests/testmod.c | 7 |
4 files changed, 31 insertions, 16 deletions
diff --git a/vendor/compat53/c-api/compat-5.3.c b/vendor/compat53/c-api/compat-5.3.c index b82c654..bf81673 100644 --- a/vendor/compat53/c-api/compat-5.3.c +++ b/vendor/compat53/c-api/compat-5.3.c @@ -37,8 +37,8 @@ #endif /* strerror_r */ #ifndef COMPAT53_HAVE_STRERROR_S -# if defined(_MSC_VER) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \ - (defined(__STDC_LIB_EXT1__) && __STDC_LIB_EXT1__) +# if defined(_MSC_VER) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && \ + defined(__STDC_LIB_EXT1__) && __STDC_LIB_EXT1__) # define COMPAT53_HAVE_STRERROR_S 1 # else /* not VC++ or C11 */ # define COMPAT53_HAVE_STRERROR_S 0 @@ -204,15 +204,6 @@ COMPAT53_API void lua_rawsetp (lua_State *L, int i, const void *p) { } -COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum) { - lua_Integer n = lua_tointeger(L, i); - if (isnum != NULL) { - *isnum = (n != 0 || lua_isnumber(L, i)); - } - return n; -} - - COMPAT53_API lua_Number lua_tonumberx (lua_State *L, int i, int *isnum) { lua_Number n = lua_tonumber(L, i); if (isnum != NULL) { @@ -740,6 +731,22 @@ COMPAT53_API int lua_isinteger (lua_State *L, int index) { } +COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum) { + int ok = 0; + lua_Number n = lua_tonumberx(L, i, &ok); + if (ok) { + if (n == (lua_Integer)n) { + if (isnum) + *isnum = 1; + return (lua_Integer)n; + } + } + if (isnum) + *isnum = 0; + return 0; +} + + static void compat53_reverse (lua_State *L, int a, int b) { for (; a < b; ++a, --b) { lua_pushvalue(L, a); diff --git a/vendor/compat53/c-api/compat-5.3.h b/vendor/compat53/c-api/compat-5.3.h index 755c23e..8e10893 100644 --- a/vendor/compat53/c-api/compat-5.3.h +++ b/vendor/compat53/c-api/compat-5.3.h @@ -165,8 +165,7 @@ COMPAT53_API void lua_rawsetp(lua_State *L, int i, const void *p); #define lua_rawlen(L, i) lua_objlen((L), (i)) -#define lua_tointegerx COMPAT53_CONCAT(COMPAT53_PREFIX, _tointegerx) -COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum); +#define lua_tointeger(L, i) lua_tointegerx((L), (i), NULL) #define lua_tonumberx COMPAT53_CONCAT(COMPAT53_PREFIX, _tonumberx) COMPAT53_API lua_Number lua_tonumberx (lua_State *L, int i, int *isnum); @@ -297,6 +296,9 @@ COMPAT53_API int lua_geti (lua_State *L, int index, lua_Integer i); #define lua_isinteger COMPAT53_CONCAT(COMPAT53_PREFIX, _isinteger) COMPAT53_API int lua_isinteger (lua_State *L, int index); +#define lua_tointegerx COMPAT53_CONCAT(COMPAT53_PREFIX, _tointegerx_53) +COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum); + #define lua_numbertointeger(n, p) \ ((*(p) = (lua_Integer)(n)), 1) diff --git a/vendor/compat53/tests/test.lua b/vendor/compat53/tests/test.lua index 2f6c7f6..c2c0abf 100755 --- a/vendor/compat53/tests/test.lua +++ b/vendor/compat53/tests/test.lua @@ -705,6 +705,11 @@ print("tonumber", mod.tonumber("error")) ___'' print("tointeger", mod.tointeger(12)) +print("tointeger", mod.tointeger(-12)) +print("tointeger", mod.tointeger(12.1)) +print("tointeger", mod.tointeger(12.9)) +print("tointeger", mod.tointeger(-12.1)) +print("tointeger", mod.tointeger(-12.9)) print("tointeger", mod.tointeger("12")) print("tointeger", mod.tointeger("0")) print("tointeger", mod.tointeger(math.pi)) diff --git a/vendor/compat53/tests/testmod.c b/vendor/compat53/tests/testmod.c index a0d2e2a..cd56e76 100644 --- a/vendor/compat53/tests/testmod.c +++ b/vendor/compat53/tests/testmod.c @@ -152,7 +152,8 @@ static int test_tointeger (lua_State *L) { lua_pushnil(L); else lua_pushinteger(L, n); - return 1; + lua_pushinteger(L, lua_tointeger(L, 1)); + return 2; } static int test_len (lua_State *L) { @@ -225,9 +226,9 @@ static int test_uservalue (lua_State *L) { int ui = lua_gettop(L); lua_newtable(L); lua_setuservalue(L, ui); - lua_getuservalue(L, ui); + lua_pushinteger(L, lua_getuservalue(L, ui)); (void)udata; - return 1; + return 2; } static int test_upvalues (lua_State *L) { |