diff options
author | Philipp Janda <siffiejoe@gmx.net> | 2018-01-13 19:57:19 +0100 |
---|---|---|
committer | Philipp Janda <siffiejoe@gmx.net> | 2018-01-13 19:57:19 +0100 |
commit | 340f2f4777e8ad427a364c9c1ef562d40c60cb1d (patch) | |
tree | 1be2cc11bf9d2d59e5973faa466563a649bdc5e4 /c-api | |
parent | 30077d241b788b644fb923b4c2da628cdd2c3423 (diff) | |
download | lua-compat-5.3-340f2f4777e8ad427a364c9c1ef562d40c60cb1d.tar.gz lua-compat-5.3-340f2f4777e8ad427a364c9c1ef562d40c60cb1d.tar.bz2 lua-compat-5.3-340f2f4777e8ad427a364c9c1ef562d40c60cb1d.zip |
lua_tointeger(x) rejects non-ints for Lua 5.1.
Diffstat (limited to 'c-api')
-rw-r--r-- | c-api/compat-5.3.c | 15 | ||||
-rw-r--r-- | c-api/compat-5.3.h | 2 |
2 files changed, 13 insertions, 4 deletions
diff --git a/c-api/compat-5.3.c b/c-api/compat-5.3.c index b82c654..ebaf03f 100644 --- a/c-api/compat-5.3.c +++ b/c-api/compat-5.3.c | |||
@@ -205,11 +205,18 @@ COMPAT53_API void lua_rawsetp (lua_State *L, int i, const void *p) { | |||
205 | 205 | ||
206 | 206 | ||
207 | COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum) { | 207 | COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum) { |
208 | lua_Integer n = lua_tointeger(L, i); | 208 | int ok = 0; |
209 | if (isnum != NULL) { | 209 | lua_Number n = lua_tonumberx(L, i, &ok); |
210 | *isnum = (n != 0 || lua_isnumber(L, i)); | 210 | lua_Integer j = (lua_tointeger)(L, i); /* native lua_tointeger */ |
211 | if (isnum == NULL) | ||
212 | isnum = &ok; | ||
213 | if (ok && n == j) { | ||
214 | *isnum = 1; | ||
215 | return j; | ||
216 | } else { | ||
217 | *isnum = 0; | ||
218 | return 0; | ||
211 | } | 219 | } |
212 | return n; | ||
213 | } | 220 | } |
214 | 221 | ||
215 | 222 | ||
diff --git a/c-api/compat-5.3.h b/c-api/compat-5.3.h index 755c23e..6b6e35c 100644 --- a/c-api/compat-5.3.h +++ b/c-api/compat-5.3.h | |||
@@ -165,6 +165,8 @@ COMPAT53_API void lua_rawsetp(lua_State *L, int i, const void *p); | |||
165 | 165 | ||
166 | #define lua_rawlen(L, i) lua_objlen((L), (i)) | 166 | #define lua_rawlen(L, i) lua_objlen((L), (i)) |
167 | 167 | ||
168 | #define lua_tointeger(L, i) lua_tointegerx((L), (i), NULL) | ||
169 | |||
168 | #define lua_tointegerx COMPAT53_CONCAT(COMPAT53_PREFIX, _tointegerx) | 170 | #define lua_tointegerx COMPAT53_CONCAT(COMPAT53_PREFIX, _tointegerx) |
169 | COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum); | 171 | COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum); |
170 | 172 | ||